微信小程序的支付功能商城开发含支付功能需要多少费用

 微信小程序接入支付功能详解教程_文章_微信小程序开发
 微信小程序接入支付功能详解教程
 接入支付功能详解教程支付      第一步   进入小程序,下单,请求下单支付,调用小程序登录API来获取Openid(),生成商户订单,这些都是在小程序端完成的业务。    小程序端代码    var app = getApp();  Page({  data: {},  onLoad: function (options) {    },    wxpay: function () {  var that = this    wx.login({  success: function (res) {  console.log(res.code)    that.getOpenId(res.code)  }  });  },  getOpenId: function (code) {  var that = this;  wx.request({  url: "https://api.weixin.qq.com/sns/jscode2session?appid=wxae496c&secret=5d6a7dc60f84f7aa85253c&js_code=" + code + "&grant_type=authorization_code",  data: {},  method: 'GET',  success: function (res) {  console.log('返回openId')  console.log(res.data)  that.generateOrder(res.data.openid)  },  fail: function () {    },  complete: function () {    }  })  },    generateOrder: function (openid) {  var that = this    wx.request({  url: 'http://localhost:8070/RMS/pay_pay.action',  method: 'GET',  data: {  total_fee: '5',  body: '支付测试',  attach:'真假酒水'  },  success: function (res) {  console.log(res)  var pay = res.data    var timeStamp = pay[0].timeS  console.log("timeStamp:"+timeStamp)  var packages = pay[0].  console.log("package:"+packages)  var paySign = pay[0].payS  console.log("paySign:"+paySign)  var nonceStr = pay[0].nonceS  console.log("nonceStr:"+nonceStr)  var param = { "timeStamp": timeStamp, "package": packages, "paySign": paySign, "signType": "MD5", "nonceStr": nonceStr };  that.pay(param)  },  })  },    pay: function (param) {  console.log("支付")  console.log(param)  wx.requestPayment({  timeStamp: param.timeStamp,  nonceStr: param.nonceStr,  package: param.package,  signType: param.signType,  paySign: param.paySign,  success: function (res) {    console.log("支付")  console.log(res)  wx.navigateBack({  delta: 1,   success: function (res) {  wx.showToast({  title: '支付成功',  icon: 'success',  duration: 2000  })  },  fail: function () {    },  complete: function () {    }  })  },  fail: function (res) {    console.log("支付失败")  console.log(res)  },  complete: function () {    console.log("pay complete")  }  })  }  })    第二步   调用支付统一下单API来获取prepay_id,并将小程序调起支付数据需要签名的字段appId,timeStamp,nonceStr,package再次签名()    后台代码  package cn.it.shop.  import java.io.ByteArrayInputS  import java.io.InputS  import java.io.UnsupportedEncodingE  import java.text.SimpleDateF  import java.util.Date;  import java.util.HashM  import java.util.List;  import java.util.Map;  import org.dom4j.D  import org.dom4j.DocumentE  import org.dom4j.E  import org.dom4j.io.SAXR  import cn.it.shop.util.MessageU  import cn.it.shop.util.PayU  import cn.it.shop.util.PaymentPo;  import cn.it.shop.util.UUIDHexG  import net.sf.json.JSONA  import net.sf.json.JSONO    * @author  * @version 创建时间:日 下午4:59:03  * 小程序端请求的后台action,返回签名后的数据传到前台  */  public class PayAction {  private String total_  private String  private String  private String  private String time_  private String time_  private String  private JSONArray jsonArray=new JSONArray();  public String pay() throws UnsupportedEncodingException, DocumentException{  body = new String(body.getBytes("UTF-8"),"ISO-8859-1");  String appid = "替换为自己的小程序ID";  String mch_id = "替换为自己的商户号";  String nonce_str = UUIDHexGenerator.generate();  String today = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());  String code = PayUtil.createCode(8);  String out_trade_no = mch_id+today+  String spbill_create_ip = "替换为自己的终端IP";  String notify_url = "http://www.weixin.qq.com/wxpay/pay.php";  String trade_type = "JSAPI";  String openid="替换为用户的openid";    PaymentPo paymentPo = new PaymentPo();  paymentPo.setAppid(appid);  paymentPo.setMch_id(mch_id);  paymentPo.setNonce_str(nonce_str);  String newbody=new String(body.getBytes("ISO-8859-1"),"UTF-8");  paymentPo.setBody(newbody);  paymentPo.setOut_trade_no(out_trade_no);  paymentPo.setTotal_fee(total_fee);  paymentPo.setSpbill_create_ip(spbill_create_ip);  paymentPo.setNotify_url(notify_url);  paymentPo.setTrade_type(trade_type);  paymentPo.setOpenid(openid);    Map&String, String& sParaTemp = new HashMap&String, String&();  sParaTemp.put("appid", paymentPo.getAppid());  sParaTemp.put("mch_id", paymentPo.getMch_id());  sParaTemp.put("nonce_str", paymentPo.getNonce_str());  sParaTemp.put("body",
paymentPo.getBody());  sParaTemp.put("out_trade_no", paymentPo.getOut_trade_no());  sParaTemp.put("total_fee",paymentPo.getTotal_fee());  sParaTemp.put("spbill_create_ip", paymentPo.getSpbill_create_ip());  sParaTemp.put("notify_url",paymentPo.getNotify_url());  sParaTemp.put("trade_type", paymentPo.getTrade_type());  sParaTemp.put("openid", paymentPo.getOpenid());    Map&String, String& sPara = PayUtil.paraFilter(sParaTemp);  String prestr = PayUtil.createLinkString(sPara);   String key = "&key=替换为商户支付密钥";     String mysign = PayUtil.sign(prestr, key, "utf-8").toUpperCase();  paymentPo.setSign(mysign);    String respXml = MessageUtil.messageToXML(paymentPo);    respXml = respXml.replace("__", "_");  String url = "https://api.mch.weixin.qq.com/pay/unifiedorder";  String param = respX    String result =PayUtil.httpRequest(url, "POST", param);    Map&String, String& map = new HashMap&String, String&();  InputStream in=new ByteArrayInputStream(result.getBytes());    SAXReader reader = new SAXReader();  Document document = reader.read(in);    Element root = document.getRootElement();    @SuppressWarnings("unchecked")  List&Element& elementList = root.elements();  for (Element element : elementList) {  map.put(element.getName(), element.getText());  }    String return_code = map.get("return_code");  String return_msg = map.get("return_msg");  System.out.println("return_msg"+return_msg);  JSONObject JsonObject=new JSONObject() ;  if(return_code=="SUCCESS"||return_code.equals(return_code)){    String prepay_id = map.get("prepay_id");  String nonceStr=UUIDHexGenerator.generate();  JsonObject.put("nonceStr", nonceStr);  JsonObject.put("package", "prepay_id="+prepay_id);  Long timeStamp= System.currentTimeMillis()/1000;  JsonObject.put("timeStamp", timeStamp+"");  String stringSignTemp = "appId="+appid+"&nonceStr=" + nonceStr + "&package=prepay_id=" + prepay_id+ "&signType=MD5&timeStamp=" + timeS    String paySign=PayUtil.sign(stringSignTemp, "&key=替换为自己的密钥", "utf-8").toUpperCase();  JsonObject.put("paySign", paySign);  jsonArray.add(JsonObject);  }  return "pay";  }  public String getTotal_fee() {  return total_  }  public void setTotal_fee(String total_fee) {  this.total_fee = total_  }  public String getBody() {  return  }  public void setBody(String body) {  this.body =  }  public JSONArray getJsonArray() {  return jsonA  }  public void setJsonArray(JSONArray jsonArray) {  this.jsonArray = jsonA  }  public String getDetail() {  return  }  public void setDetail(String detail) {  this.detail =  }  public String getAttach() {  return  }  public void setAttach(String attach) {  this.attach =  }  public String getTime_start() {  return time_  }  public void setTime_start(String time_start) {  this.time_start = time_  }  public String getTime_expire() {  return time_  }  public void setTime_expire(String time_expire) {  this.time_expire = time_  }  public String getOpenid() {  return  }  public void setOpenid(String openid) {  this.openid =  }  }      后台业务逻辑涉及到的工具类及参数封装类      MessageUtil  package cn.it.shop.  import java.io.IOE  import java.io.W  import java.util.HashM  import java.util.L  import javax.servlet.http.HttpServletR  import org.dom4j.D  import org.dom4j.E  import org.dom4j.io.SAXR  import com.thoughtworks.xstream.XS  import com.thoughtworks.xstream.core.util.QuickW  import com.thoughtworks.xstream.io.HierarchicalStreamW  import com.thoughtworks.xstream.io.xml.PrettyPrintW  import com.thoughtworks.xstream.io.xml.XppD  public class MessageUtil {  public static HashMap&String,String& parseXML(HttpServletRequest request) throws Exception, IOException{  HashMap&String,String& map=new HashMap&String,String&();    SAXReader reader = new SAXReader();  Document doc = reader.read(request.getInputStream());    Element root=doc.getRootElement();  recursiveParseXML(root,map);  return  }  private static void recursiveParseXML(Element root,HashMap&String,String& map){    List&Element& elementList=root.elements();    if(elementList.size()==0){  map.put(root.getName(), root.getTextTrim());  }  else{    for(Element e:elementList){  recursiveParseXML(e,map);  }  }  }  private static XStream xstream = new XStream(new XppDriver() {  public HierarchicalStreamWriter createWriter(Writer out) {  return new PrettyPrintWriter(out) {    boolean cdata = true;  public void startNode(String name, Class clazz) {  super.startNode(name, clazz);  }  protected void writeText(QuickWriter writer, String text) {  if (cdata) {  writer.write("&![CDATA[");  writer.write(text);  writer.write("]]&");  } else {  writer.write(text);  }  }  };  }  });  public static String messageToXML(PaymentPo paymentPo){  xstream.alias("xml",PaymentPo.class);  return xstream.toXML(paymentPo);  }  }  PaymentPo  package cn.it.shop.  /**  *  * 创建时间:日 下午4:20:52  * 类说明  */  public class PaymentPo {  private S  private String mch_  private String device_  private String nonce_  private S  private S  private S  private S  private String out_trade_  private String fee_  private String spbill_create_  private String time_  private String time_  private String goods_  private String total_  private String notify_  private String trade_  private String limit_  private S  public String getAppid() {  return  }  public void setAppid(String appid) {  this.appid =  }  public String getMch_id() {  return mch_  }  public void setMch_id(String mch_id) {  this.mch_id = mch_  }  public String getNonce_str() {  return nonce_  }  public void setNonce_str(String nonce_str) {  this.nonce_str = nonce_  }  public String getSign() {  return  }  public void setSign(String sign) {  this.sign =  }  public String getBody() {  return  }  public void setBody(String body) {  this.body =  }  public String getOut_trade_no() {  return out_trade_  }  public void setOut_trade_no(String out_trade_no) {  this.out_trade_no = out_trade_  }  public String getTotal_fee() {  return total_  }  public void setTotal_fee(String total_fee) {  this.total_fee = total_  }  public String getNotify_url() {  return notify_  }  public void setNotify_url(String notify_url) {  this.notify_url = notify_  }  public String getTrade_type() {  return trade_  }  public void setTrade_type(String trade_type) {  this.trade_type = trade_  }  public String getOpenid() {  return  }  public void setOpenid(String openid) {  this.openid =  }  public String getSpbill_create_ip() {  return spbill_create_  }  public void setSpbill_create_ip(String spbill_create_ip) {  this.spbill_create_ip = spbill_create_  }  public String getDevice_info() {  return device_  }  public void setDevice_info(String device_info) {  this.device_info = device_  }  public String getDetail() {  return  }  public void setDetail(String detail) {  this.detail =  }  public String getAttach() {  return  }  public void setAttach(String attach) {  this.attach =  }  public String getFee_type() {  return fee_  }  public void setFee_type(String fee_type) {  this.fee_type = fee_  }  public String getTime_start() {  return time_  }  public void setTime_start(String time_start) {  this.time_start = time_  }  public String getTime_expire() {  return time_  }  public void setTime_expire(String time_expire) {  this.time_expire = time_  }  public String getGoods_tag() {  return goods_  }  public void setGoods_tag(String goods_tag) {  this.goods_tag = goods_  }  public String getLimit_pay() {  return limit_  }  public void setLimit_pay(String limit_pay) {  this.limit_pay = limit_  }  }  PayUtil  package cn.it.shop.  import java.io.BufferedR  import java.io.InputS  import java.io.InputStreamR  import java.io.OutputS  import java.io.UnsupportedEncodingE  import java.net.HttpURLC  import java.net.URL;  import java.util.ArrayL  import java.util.C  import java.util.HashM  import java.util.L  import java.util.M  import org.apache.commons.codec.digest.DigestU  /**  *  * 创建时间:日 下午7:46:29 类说明  */  public class PayUtil {  /**  * 签名字符串  * text需要签名的字符串  * key 密钥  * input_charset编码格式  * 签名结果  */  public static String sign(String text, String key, String input_charset) {  text = text +  return DigestUtils.md5Hex(getContentBytes(text, input_charset));  }  /**  * 签名字符串  *
text需要签名的字符串  * sign 签名结果  * key密钥  * input_charset 编码格式  * 签名结果  */  public static boolean verify(String text, String sign, String key, String input_charset) {  text = text +  String mysign = DigestUtils.md5Hex(getContentBytes(text, input_charset));  if (mysign.equals(sign)) {  return true;  } else {  return false;  }  }  /**  * content  * charset  *  * SignatureException  * UnsupportedEncodingException  */  public static byte[] getContentBytes(String content, String charset) {  if (charset == null || "".equals(charset)) {  return content.getBytes();  }  try {  return content.getBytes(charset);  } catch (UnsupportedEncodingException e) {  throw new RuntimeException("MD5签名过程中出现错误,指定的编码集不对,您目前指定的编码集是:" + charset);  }  }  /**  * 生成6位或10位随机数 param codeLength(多少位)  *  */  public static String createCode(int codeLength) {  String code = "";  for (int i = 0; i & codeL i++) {  code += (int) (Math.random() * 9);  }  return  }  private static boolean isValidChar(char ch) {  if ((ch &= '0' && ch &= '9') || (ch &= 'A' && ch &= 'Z') || (ch &= 'a' && ch &= 'z'))  return true;  if ((ch &= 0x4e00 && ch &= 0x7fff) || (ch &= 0x8000 && ch &= 0x952f))  return true;  return false;  }  /**  * 除去数组中的空值和签名参数  * sArray 签名参数组  * 去掉空值与签名参数后的新签名参数组  */  public static Map&String, String& paraFilter(Map&String, String& sArray) {  Map&String, String& result = new HashMap&String, String&();  if (sArray == null || sArray.size() &= 0) {  return  }  for (String key : sArray.keySet()) {  String value = sArray.get(key);  if (value == null || value.equals("") || key.equalsIgnoreCase("sign")  || key.equalsIgnoreCase("sign_type")) {  continue;  }  result.put(key, value);  }  return  }  /**  * 把数组所有元素排序,并按照“参数=参数值”的模式用“&”字符拼接成字符串  * params 需要排序并参与字符拼接的参数组  * 拼接后字符串  */  public static String createLinkString(Map&String, String& params) {  List&String& keys = new ArrayList&String&(params.keySet());  Collections.sort(keys);  String prestr = "";  for (int i = 0; i & keys.size(); i++) {  String key = keys.get(i);  String value = params.get(key);  if (i == keys.size() - 1) {  prestr = prestr + key + "=" +  } else {  prestr = prestr + key + "=" + value + "&";  }  }  return  }  /**  *  * requestUrl请求地址  * requestMethod请求方法  * outputStr参数  */  public static String httpRequest(String requestUrl,String requestMethod,String outputStr){    StringBuffer buffer=null;  try{  URL url = new URL(requestUrl);  HttpURLConnection conn = (HttpURLConnection) url.openConnection();  conn.setRequestMethod(requestMethod);  conn.setDoOutput(true);  conn.setDoInput(true);  conn.connect();    if(null !=outputStr){  OutputStream os=conn.getOutputStream();  os.write(outputStr.getBytes("utf-8"));  os.close();  }    InputStream is = conn.getInputStream();  InputStreamReader isr = new InputStreamReader(is, "utf-8");  BufferedReader br = new BufferedReader(isr);  buffer = new StringBuffer();  String line = null;  while ((line = br.readLine()) != null) {  buffer.append(line);  }  }catch(Exception e){  e.printStackTrace();  }  return buffer.toString();  }  public static String urlEncodeUTF8(String source){  String result=  try {  result=java.net.URLEncoder.encode(source, "UTF-8");  } catch (UnsupportedEncodingException e) {    e.printStackTrace();  }  return  }  }  UUIDHexGenerator  package cn.it.shop.  import java.net.InetA  /**  *  * 创建时间:日 下午7:45:06 类说明  */  public class UUIDHexGenerator {  private static String sep = "";  private static final int IP;  private static short counter = (short) 0;  private static final int JVM = (int) (System.currentTimeMillis() &&& 8);  private static UUIDHexGenerator uuidgen = new UUIDHexGenerator();  static {  int  try {  ipadd = toInt(InetAddress.getLocalHost().getAddress());  } catch (Exception e) {  ipadd = 0;  }  IP =  }  public static UUIDHexGenerator getInstance() {  return  }  public static int toInt(byte[] bytes) {  int result = 0;  for (int i = 0; i & 4; i++) {  result = (result && 8) - Byte.MIN_VALUE + (int) bytes[i];  }  return  }  protected static String format(int intval) {  String formatted = Integer.toHexString(intval);  StringBuffer buf = new StringBuffer("");  buf.replace(8 - formatted.length(), 8, formatted);  return buf.toString();  }  protected static String format(short shortval) {  String formatted = Integer.toHexString(shortval);  StringBuffer buf = new StringBuffer("0000");  buf.replace(4 - formatted.length(), 4, formatted);  return buf.toString();  }  protected static int getJVM() {  return JVM;  }  protected synchronized static short getCount() {  if (counter & 0) {  counter = 0;  }  return counter++;  }  protected static int getIP() {  return IP;  }  protected static short getHiTime() {  return (short) (System.currentTimeMillis() &&& 32);  }  protected static int getLoTime() {  return (int) System.currentTimeMillis();  }  public static String generate() {  return new StringBuffer(36).append(format(getIP())).append(sep).append(format(getJVM())).append(sep)  .append(format(getHiTime())).append(sep).append(format(getLoTime())).append(sep)  .append(format(getCount())).toString();  }  /**  * args  */  public static void main(String[] args) {  String id="";  UUIDHexGenerator uuid = UUIDHexGenerator.getInstance();    for (int i = 0; i & 100; i++) {  id = uuid.generate();  }*/  id = uuid.generate();  System.out.println(id);  }  }  第一次写,写的不是太完整,希望同大家多多交流,一起进步。      
1520阅读 | 1评论
18:02:10 <a
href="http://www.mntuku.cn/index.php/user/space/id-164
对所有传入参数按照字段名的 ASCII 码 从小到大排序(字典序)后,使用 URL 键值对的
格式(即 key1=value1&key2=value2…)拼接成字符串 string1, 注意: 值为空的参数不参与
资深程序猿教你搭建手机直播系统直播源码!
花小钱如何做直播软件平台或直播盒子直播系统源码!
手机直播软件系统搭建源码,聚合采集器采集平台接口!
云豹方维直播源码,手机直播系统搭建经验分享!
直播APP开发:直播源码流媒体技术介绍!
个人如何搭建专属直播系统方维直播源码2.5版!
微信小程序连接好新浪云,数据传参无返回值
分享一个精品JAVA微信小程序商城源码
手机直播源码开发直播系统经验分享!
开发直播源码直播系统直播App成本有多大?
选择优秀的直播源码开发公司,完成2018小目标!
bogo手机直播源码部署直播软件系统搭建!
遇到此类问题 调试正常 体验版本手机端不显示
Thinkphp3.2新版推荐微信语音小程序口令红包源码
在线手机直播系统源码搭建!
有人承接外包的吗?我想做一款微信小程序

我要回帖

更多关于 微信小程序开发费用 的文章

 

随机推荐