我用真机调试的时候能够调用支付的功能 。也能支付成功。怎么上传发布后就不行了。出不来微信支付的窗口。下面是我的支付页面
var common = require("../../utils/util.js");
var md5 = require('../../utils/md5.js');
var Parser = require('../../lib/dom-parser.js')
var app = getApp();
const imgurl = app.globalData.imgUrl;
Page({
/**
* 页面的初始数据
*/
data: {
truename: '',
uuid: '',
uopendid: wx.getStorageSync('useropendid'),
dingdanhao: '',
is_default: 0,
mobile: '398',
address_id: wx.getStorageSync('address'),
action: 'submitAddress',
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
//this.data.uuid = options.uid;
// this.data.dingdanhao = options.uid + 'sj' + common.createTimeStamp();
//this.data.truename = options.uname;//wx.getStorageSync('huiyuanid');
this.setData({uuid: options.uid});
this.setData({ dingdanhao: options.uid + 'sj' + common.createTimeStamp() });
this.setData({ truename: options.uname });
},
//点击充值时执行
submitAddress: function (e) {
var that = this
//var jines = e.detail.jine
//var username = co97468869746886mmon.getUserName()
var data_post = e.detail.value
that.unitedPayRequest(wx.getStorageSync('useropendid'), data_post.jine, this.data.dingdanhao);
},
/*统一支付接口*/
unitedPayRequest: function (openid,zfje,ddh) {
var that = this;
//统一支付签名
this.setData({ mobile: zfje});
var appid = 'wx10cadf512ecc5555';//appid必填
var body = 'chongzhi';//商品名必填
var mch_id = '1537265555';//商户号必填
var nonce_str = common.randomString();//随机字符串,不长于32位。
var notify_url = 'https://aa.bb.com/wapxcx/ResultNotifyPage.aspx';//通知地址必填
var total_fee = parseInt(zfje * 100); //价格,这是一分钱
var trade_type = "JSAPI";
var key = '11111111111111111111111111111111'; //商户key必填,在商户后台获得
var out_trade_no = this.data.uuid + 'sj' + common.createTimeStamp();//自定义订单号必填
var spbill_create_ip ='123.12.12.123';
var unifiedPayment = 'appid=' + appid + '&body=' + body + '&mch_id=' + mch_id + '&nonce_str=' + nonce_str + '¬ify_url=' + notify_url + '&openid=' + openid + '&out_trade_no=' + out_trade_no + '&spbill_create_ip=' + spbill_create_ip+'&total_fee=' + total_fee + '&trade_type=' + trade_type + '&key=' + key;
//"appid=" + APPID + "&body=chongzhi&mch_id=" + MCHID + "&nonce_str=" + sjs + "¬ify_url=" + fhlj + "&openid=" + oid.Text + "&out_trade_no=" + ddh + "&spbill_create_ip=" + ip + "&total_fee=" + je + "&trade_type=" + trade_type + "&key=" + KEY + "";
//console.log("unifiedPayment", unifiedPayment);
var sign = md5.hexMD5(unifiedPayment).toUpperCase();
//console.log("签名md5", sign);
/*
wx.setStorageSync('nrs', unifiedPayment+">"+sign);//存储
wx.redirectTo({
url: '../woxinxi/woxinxi'
})*/
//封装统一支付xml参数
var formData = "<xml>";
formData += "<appid>" + appid + "</appid>";
formData += "<body>" + body + "</body>";
formData += "<mch_id>" + mch_id + "</mch_id>";
formData += "<nonce_str>" + nonce_str + "</nonce_str>";
formData += "<notify_url>" + notify_url + "</notify_url>";
formData += "<openid>" + openid + "</openid>";
formData += "<out_trade_no>" + out_trade_no+ "</out_trade_no>";
formData += "<spbill_create_ip>" + spbill_create_ip + "</spbill_create_ip>";
formData += "<total_fee>" + total_fee + "</total_fee>";
formData += "<trade_type>" + trade_type + "</trade_type>";
formData += "<sign>" + sign + "</sign>";
formData += "</xml>";
//console.log("formData", formData);
/*wx.showToast({
title: formData,
icon: 'success',
duration: 2000
}) */
//统一支付
wx.request({
url: 'https://api.mch.weixin.qq.com/pay/unifiedorder', //别忘了把api.mch.weixin.qq.com域名加入小程序request白名单,这个目前可以加
method: 'POST',
head: 'application/x-www-form-urlencoded',
data: formData, //设置请求的 header
success: function (res) {
//console.log("返回商户", res.data);
/**/
var xml = res.data.toString("utf-8");
var tmp = xml.split("<result_code>")
var result_code = tmp[1].split("</result_code>")
var resultCode = result_code[0].split('[')[2].split(']')[0];
if (resultCode == 'FAIL') {
var err_code_des = common.getXMLNodeValue('err_code_des', res.data.toString("utf-8"));
var errDes = err_code_des.split('[')[2].split(']')[0];
wx.showToast({
title: errDes,
icon: 'success',
duration: 2000
})
} else
{
//发起支付
var prepay_id = common.getXMLNodeValue('prepay_id', res.data.toString("utf-8"));
var tmp = prepay_id.split('[');
var tmp1 = tmp[2].split(']');
//签名
var key = 'Yhjkloiuyhjklkj765yujkjhgy678jkj';//商户key必填,在商户后台获得
var appId = 'wx10cadf512ecc81da';//appid必填
var timeStamp = common.createTimeStamp();
var nonceStr = common.randomString();
var stringSignTemp = "appId=" + appId + "&nonceStr=" + nonceStr + "&package=prepay_id=" + tmp1[0] + "&signType=MD5&timeStamp=" + timeStamp + "&key=" + key;
// console.log("签名字符串", stringSignTemp);
var sign = md5.hexMD5(stringSignTemp).toUpperCase();
//console.log("签名", sign);
var param = { "timeStamp": timeStamp, "package": 'prepay_id=' + tmp1[0], "paySign": sign, "signType": "MD5", "nonceStr": nonceStr }
// console.log("param小程序支付接口参数", param);
that.processPay(param);
}
},
})
},//unitedPayRequest()
/* 小程序支付 */
processPay: function (param) {
var that = this;
wx.requestPayment({
timeStamp: param.timeStamp,
nonceStr: param.nonceStr,
package: param.package,
signType: param.signType,
paySign: param.paySign,
success: function (res) {
// success
//console.log("wx.requestPayment返回信息", res);
wx.showModal({
title: '支付成功',
content: '您将在“微信支付”官方号中收到支付凭证',
showCancel: false,
success: function (res) {
common.httpP('chongzhixcx.aspx', {
truenames: that.data.truename,
jines: that.data.mobile,
uid: that.data.uuid,
ddh: that.data.dingdanhao,
}, function (data) {
if (data.code == 0) {
//wx.setStorageSync('huiyuanname', data.data.username);
//wx.setStorageSync('huiyuanid', data.data.userid);
}
})
if (res.confirm)
{
}
else if (res.cancel)
{
}
}
})
},
fail: function () {
// console.log("支付失败");
},
complete: function () {
// console.log("支付完成(成功或失败都为完成)");
}
})
},//processPay()
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
// this.onLoad();
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})
微信支付的文档里,要求商户订单号out_trade_no为32个字符内。你用了UUID吧?再拼接时间戳,超过32位了吧?能调试过关?没报错?
您好,开发问题需要商户自己解决噢 可以参考官网上的最新版SDK https://pay.weixin.qq.com/wiki/doc/api/index.html