当前位置:网站首页>Wechat payment function
Wechat payment function
2022-04-23 04:45:00 【Zhou zhouchi】
I'm going to pay WeChat
In the previously completed wechat applet , Wechat payment functions are used more , Take a note
Wechat payment can be spliced through the front end , It can also be spliced through the back end , Call and submit order interface , Get the corresponding parameters
Front splicing , V2 The way
Parameters required for wechat payment , First call the unified ordering interface to obtain parameters
-
appid , The account number applied by wechat open platform corresponds to appid It is also a small program appid
-
timeStamp, Time ( Timestamp format )
-
package, payment ID( Splicing format
'prepay_id=' + prepay_id
, The following is payment ID) -
signType, Encryption method of signature ( It is recommended to use md5)
-
nonceStr, random number
-
paySign, Signature ,( This is the most important ) Splicing method
let stringSignTemp = 'appId=' + myappid + '&nonceStr=' + myRanDomeStr + '&package=' + myprepay_id + '&signType=MD5&timeStamp=' + myTtate_Str + '&key=Ksv7jqvK3K7rB4mvOwWiqKwMuaaiSY66' let paySign = md5(stringSignTemp).toUpperCase()
Have you noticed , The attribute names of all parameters start with lowercase , This is something to pay attention to , Otherwise, when you adjust the payment , Will promptpaySign
Field error .Front end splicing source code
WeiXinPay(appid, nonce_str, prepay_id, sign, order_sn) { // Order payment this.getonav=1 let myappid = appid //openid let myTtate_Str = String(Date.now()) // Current timestamp let myRanDomeStr = this.randomString() // random number let myprepay_id = 'prepay_id=' + prepay_id // payment id let stringSignTemp = 'appId=' + myappid + '&nonceStr=' + myRanDomeStr + '&package=' + myprepay_id + '&signType=MD5&timeStamp=' + myTtate_Str + '&key=Ksv7jqvK3K7rB4mvOwWiqKwMuaaiSY66' let paySign = md5(stringSignTemp).toUpperCase() uni.requestPayment({ provider: 'wxpay', timeStamp: myTtate_Str, nonceStr: myRanDomeStr, package: myprepay_id, signType: 'MD5', paySign: paySign, success: function(res) { console.log(" success ") console.log('success:' + JSON.stringify(res)); uni.redirectTo({ url: `/Tosubpages/pages/TheOrderDetails/TheOrderDetails?order_sn=${ order_sn}&Order_static=2&getonav=1` }); }, fail: function(err) { console.error(" Failure ") } }); },
Backend return , V3 The way
This is friendly to the front end , Just call the interface to get parameters
Source code
WxAlipay(order_id, order_sn) {
let that = this
wxpay(order_id).then(res => {
if (res.data.code == 0) {
let OrderReference = order_sn // The order no.
let OrderTime = that.formatDate(new Date(res.data.data.timeStamp*1000)) // Order time
uni.requestPayment({
provider: 'wxpay',
timeStamp: res.data.data.timeStamp, // Time
nonceStr: res.data.data.nonceStr, // random number
package: res.data.data.package, // payment ID
signType: res.data.data.signType, // encryption
paySign: res.data.data.paySign, // Signature
success: function(res) {
console.log(" success ")
console.log('success:' + JSON.stringify(res));
uni.redirectTo({
url: `/Tosubpages/pages/PaymentSuccess?&OrderReference=${
OrderReference}&OrderTime=${
OrderTime}`
});
},
fail: function(err) {
uni.redirectTo({
url: `/Tosubpages/pages/OrderDetails?&ordertype=0&order_id=${
order_id}`
});
}
});
}
}).catch(Error => {
console.error(Error)
})
},
版权声明
本文为[Zhou zhouchi]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220557472594.html
边栏推荐
- QML advanced (V) - realize all kinds of cool special effects through particle simulation system
- leetcode001--返回和为target的数组元素的下标
- QML进阶(五)-通过粒子模拟系统实现各种炫酷的特效
- 针对NFT的网络钓鱼
- Spark small case - RDD, broadcast
- Better way to read configuration files than properties
- Phishing for NFT
- Improving 3D object detection with channel wise transformer
- Gets all dates between two times
- 基于英飞凌MCU GTM模块的无刷电机驱动方案开源啦
猜你喜欢
Summary of Android development posts I interviewed in those years (attached test questions + answer analysis)
229. Find mode II
使用model.load_state_dict()时,出现AttributeError: ‘str‘ object has no attribute ‘copy‘
Supplement 14: cmake practice project notes (to be continued 4 / 22)
协程与多进程的完美结合
520. Detect capital letters
Spark small case - RDD, spark SQL
Recommended scheme of national manufactured electronic components
Recommended scheme for national production of electronic components for wireless charging
Installation of zynq platform cross compiler
随机推荐
The last day of 2021 is the year of harvest.
zynq平台交叉编译器的安装
Special topic of data intensive application system design
229. Find mode II
补充番外14:cmake实践项目笔记(未完待续4/22)
leetcode004--罗马数字转整数
Recommended scheme of national manufactured electronic components
Bridge between ischemic stroke and intestinal flora: short chain fatty acids
La caméra Unity tourne avec la souris
What is the thirty-six plan
那些年我面试过的Android开发岗总结(附面试题+答案解析)
Youqilin 22.04 lts version officially released | ukui 3.1 opens a new experience
IDE idea automatic compilation and configuration of on update action and on frame deactivation
Summary of MySQL de duplication methods
Installation of zynq platform cross compiler
Record the blind injection script
Phishing for NFT
Unity摄像头跟随鼠标旋转
电钻、电锤、电镐的区别
Recommended scheme of national manufactured electronic components for intelligent electronic scales