当前位置:网站首页>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 promptpaySignField 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
边栏推荐
- [pytoch foundation] torch Split() usage
- leetcode008--实现strStr()函数
- [paper reading] [3D object detection] voxel transformer for 3D object detection
- 使用model.load_state_dict()时,出现AttributeError: ‘str‘ object has no attribute ‘copy‘
- 阿里十年技术专家联合打造“最新”Jetpack Compose项目实战演练(附Demo)
- 229. Find mode II
- La caméra Unity tourne avec la souris
- Shanghai Hangxin technology sharing 𞓜 overview of safety characteristics of acm32 MCU
- Unity3D 实用技巧 - 理论知识库(一)
- Eight misunderstandings that should be avoided in data visualization
猜你喜欢

简单的拖拽物体到物品栏
![[paper reading] [3D target detection] point transformer](/img/c5/b1fe5f206b5fe6e4dcd88dce11592d.png)
[paper reading] [3D target detection] point transformer

那些年我面试过的Android开发岗总结(附面试题+答案解析)

Go reflection rule

The perfect combination of collaborative process and multi process

Coinbase:关于跨链桥的基础知识、事实和统计数据

What is a data island? Why is there still a data island in 2022?

针对NFT的网络钓鱼

Ali's ten-year technical experts jointly created the "latest" jetpack compose project combat drill (with demo)

Recommended scheme of national manufactured electronic components for intelligent electronic scales
随机推荐
Windows remote connection to redis
[timing] empirical evaluation of general convolution and cyclic networks for sequence modeling based on TCN
Redis 命令大全
Coinbase: basic knowledge, facts and statistics about cross chain bridge
Go reflection rule
win10, mysql-8.0.26-winx64. Zip installation
IEEE Transactions on industrial information (TII)
使用model.load_state_dict()时,出现AttributeError: ‘str‘ object has no attribute ‘copy‘
QML进阶(五)-通过粒子模拟系统实现各种炫酷的特效
Use recyclerview to realize left-right side-by-side classification selection
协程与多进程的完美结合
General enumeration constant class
Summary of Android development posts I interviewed in those years (attached test questions + answer analysis)
Simply drag objects to the item bar
Recommended scheme for national production of electronic components for wireless charging
Unity camera rotation with sliding effect (rotation)
Differences among electric drill, electric hammer and electric pick
Unity攝像頭跟隨鼠標旋轉
Leetcode001 -- returns the subscript of the array element whose sum is target
POI export message list (including pictures)