发现小程序的这个问题非常诡异
首先,我从服务器获取到了五个必须的字段,这五个字段,我如果直接在代码里面写死数据,可以直接调起支付,没有问题.
当我直接把拿到的数据赋值给wx . requestPayment,作为参数的时候,会出现错误,-1的情况就出现了.
我的具体代码如下
success : function ( res ) {
wx . showToast ({
title : '创建订单成功' ,
duration : 1000 ,
mask : true
})
console . log ( res );
var time = String ( res . data . data . timeStamp )
var nonce = String ( res . data . data . nonceStr )
var packageName = String ( res . data . data . packageValue )
var pay = String ( res . data . data . paySign )
var sign = String ( res . data . data . signType )
console . log ( time )
console . log ( nonce )
console . log ( packageName )
console . log ( pay )
console . log ( sign )
wx . requestPayment ({
'timeStamp' : time ,
'nonceStr' : nonce ,
'package' : packageName ,
'signType' : 'MD5' ,
'paySign' : sign ,
success : function ( res ) {
console . log ( "success" );
console . log ( res );
},
fail : function ( res ) {
console . log ( "fail" );
console . log ( res );
},
complete : function ( res ) {
console . log ( "complete" );
console . log ( res );
}
})
}
代码对应的控制台输出如下
{data: {…}, header: {…}, statusCode: 200, errMsg: "request:ok"}data: code: 0data: appId: "wxc3c8295cb8a9c3d8"nonceStr: "1530760287929"packageValue: "prepay_id=wx051111278716365a8b8d5f3e0644257598"paySign: "CE7713C270DF032CF76F34C7D67B08BA"signType: "MD5"timeStamp: "1530760287"__proto__: Objectdesc: "成功"__proto__: ObjecterrMsg: "request:ok"header: {Content-Type: "application/json;charset=UTF-8", Date: "Thu, 05 Jul 2018 03:11:27 GMT", Vary: "Accept-Encoding", Content-Length: "242"}statusCode: 200__proto__: Object
11:11:28.016 pay.js? [sm]:177 1530760287
11:11:28.017 pay.js? [sm]:178 1530760287929
11:11:28.018 pay.js? [sm]:179 prepay_id=wx051111278716365a8b8d5f3e0644257598
11:11:28.018 pay.js? [sm]:180 CE7713C270DF032CF76F34C7D67B08BA
11:11:28.019 pay.js? [sm]:181 MD5
11:11:37.733 pay.js? [sm]:196 fail
11:11:37.734 pay.js? [sm]:197 {err_code: "-1", err_desc: "支付验证签名失败", errMsg: "requestPayment:fail"}
但是控制台输出的数据,我直接把控制台参数写死代码就可以调用支付,这个微信的好奇怪啊,难道跟编码有关系么?
我如果直接复制控制台参数到代码里面,直接可以过,而且调用起来微信没有问题.
wx . requestPayment ({
'timeStamp' : '1530760287' ,
'nonceStr' : '1530760287929' ,
'package' : 'prepay_id=wx051111278716365a8b8d5f3e0644257598' ,
'signType' : 'MD5' ,
'paySign' : 'CE7713C270DF032CF76F34C7D67B08BA' ,
success : function ( res ) {
console . log ( "success" );
console . log ( res );
},
fail : function ( res ) {
console . log ( "fail" );
console . log ( res );
},
complete : function ( res ) {
console . log ( "complete" );
console . log ( res );
}
})
小程序的bug?我已经实验过好多次了,就是这样的.不知道原因.
希望小程序的开发人员看看这个问题原因,我从接口获取数据,传递给wx.requestPayment就无法通过,我如果把数据直接写死就没问题,而且我已经对参数做了字符串处理,依然错误,希望尽快给个解决办法.目前我无法解决这个问题了.