1. 程式人生 > >微信小程式支付遇到的坑

微信小程式支付遇到的坑

1,微信公眾號支付和微信小程式支付有差異

 微信公眾號:可以直接跳轉走h5的微信支付

微信小程式:在測試環境、沙箱環境使用微信公眾號的跳轉支付沒有問題,在線上存在支付異常

最後商討的解決方法

 openid獲取的方法------appid----code----apenid,accestoken

通過appenid拿到對應的驗籤--

{"code":0,"data":{"onlyCardPay":false,"paramStr":"{\"appId\":\"wx42717f54417ecce1\",\"nonceStr\":\"jf3nrssre50imqiw7odgrg37l2xbd0kd\",\"package\":\"prepay_id=wx081219379987660ba709d52d3193336979\",\"paySign\":\"C60C1DB483CD8C9A7DA518C3CE11CAD8\",\"signType\":\"MD5\",\"timeStamp\":\"1546921178\"}","payChannel":"wx_xcx","payOrderId":"281975780250193921","paySuccessUrl":"https://minisite.daojia.com/pt/topic/collage2/index.html?productId=237&orderId=615469211711148832&groupId=154341#/orderdetail","result":true},"message":"成功","success":true} 

 業務線給我們傳遞OPENID---進入收銀臺

 去支付——收銀臺判斷當前是微信小程式,跳轉業務方提供的原聲小程式連結,進行跳轉,支付他們去支付

let url = data. paySuccessUrl let signData = data. paramStr Window. wx. miniProgram. getEnv( function ( res) { let sd = encodeURIComponent( signData) url
= `/pages/h5-weapp-pay/h5-weapp-pay?signData= ${ sd } &url= ${ url } ` if ( res. miniprogram) { if ( signData. length === 0) { // alert("signData不能為空") return false } Window. wx. miniProgram. navigateTo({ url: url
}) } })

wx.requestPayment(
{
'timeStamp''',
'nonceStr''',
'package''',
'signType''MD5',
'paySign''',
'success':function(res){
},
'fail':function(res){},
'complete':function(res){
}
})