当前位置:网站首页>WeChat payment development process
WeChat payment development process
2022-08-09 12:33:00 【Fire orchid】
Record the WeChat JSAPI payment process
1. It is judged that the WeChat browser directly requests the link authorized by WeChat, which needs to be passed to the page redirected by WeChat, and the order id
// WeChat browser calls directlyif (this.isWeixin) {let redirectUri = 'http://192.168.1.6/weChat'window.location.href = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxe0701b98700ac86e&redirect_uri='+ encodeURI(redirectUri) + '&response_type=code&scope=snsapi_base&state=' + this.order.orderId + '#wechat_redirect'}
2. After obtaining authorization in the previous step, you will get the code and the passed order id, which will be spelled on the redirected route in the form of a query, and then request the background to obtain the code and order id through the obtained code and order id.Pay the corresponding required parameters and return in the background.
created() {let _query = this.$route.queryif (Object.keys(_query).length > 0 && _query.code) {wxChatPublicPayApi({code: _query.code,orderId: _query.state}).then(res => {this.params = res.dataif (typeof WeixinJSBridge === 'undefined') {if (document.addEventListener) {document.addEventListener('WeixinJSBridgeReady', this.onBridgeReady, false)} else if (document.attachEvent) {document.attachEvent('WeixinJSBridgeReady', this.onBridgeReady)document.attachEvent('onWeixinJSBridgeReady', this.onBridgeReady)}} else {this.onBridgeReady()}})}}
3. After getting the parameters returned by the background, you can directly call the WeChat api
onBridgeReady() {let _this = thisWeixinJSBridge.invoke('getBrandWCPayRequest', _this.params, function (res) {if (res.err_msg === 'get_brand_wcpay_request:ok') {// Use the above method to judge the front-end return, the WeChat team solemnly reminds:// res.err_msg will return ok after the user pays successfully, but it is not guaranteed to be absolutely reliable._this.checkPayStatus()} else {_this.$message({message: res.err_msg + 'Payment failed',type: 'error'})_this.$router.push('/orderDetail/' + _this.$route.query.state)}})},
For detailed parameters, please refer to the following WeChat payment official documents: https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=7_7&index=6
边栏推荐
- JS 封装节流(后期优化)
- C# async 和 await 理解
- 阿里高工带来的20022最新面试总结太香了
- [Essence] Analysis of the special case of C language structure: structure pointer / basic data type pointer, pointing to other structures
- PAT1007
- [工程数学]1_特征值与特征向量
- Information system project managers must memorize the core test sites (63) The main process of project portfolio management & DIPP analysis
- 程序员的专属浪漫——用3D Engine 5分钟实现烟花绽放效果
- 《数字经济全景白皮书》银行业智能营销应用专题分析 发布
- 问题来了:4GB物理内存的机器上申请8G内存能成功吗?
猜你喜欢
bat文件(批处理文件)运行时一闪而过解决方法
How should the acceptance criteria for R&D requirements be written?| Agile Practices
元宇宙:下一代互联网启程(附元宇宙深度报告PDF)
Programmer's Exclusive Romance - Use 3D Engine to Realize Fireworks in 5 Minutes
Double pointer - the role of char **, int **
Visual Studio 2017 ASP.NET Framework MVC 项目 MySQL 配置连接
【Adobe Premiere Pro 2020】pr2020安装和基本操作【PR安装、新建项目流程、导入及管理素材项目文件、添加标记、创建出入点剪辑视频、快速剪接及自动音乐卡点的方法
LeetCode热题(11.合并两个有序链表)
MongoDB-查询中$all的用法介绍
This application has no explicit mapping for /error, so you are seeing this as a fallback
随机推荐
软件测试——金融测试类面试题,看完直接去面试了
TI的片上固化好的boot ROM(上电引导加载程序)退出后的去向
[Interview high-frequency questions] Linked list high-frequency questions that can be gradually optimized
元宇宙:下一代互联网启程(附元宇宙深度报告PDF)
Experiment record: the process of building a network
Visual Studio 2017 ASP.NET Framework MVC 项目 MySQL 配置连接
GET请求和POST请求区别
C# Get system installed .NET version
PAT1008
Programmer's Exclusive Romance - Use 3D Engine to Realize Fireworks in 5 Minutes
PAT 1015 进制转换
【Untitled】
GRPC整体学习
PM2 configuration file
matlab simulink的scope 示波器光标如何移动记录
Win10调整磁盘存储空间详解
BeanFacroty和FactoryBean到底是什么?AppliacationContext它又是什么?
redis主从复制
"Digital Economy Panorama White Paper" Special Analysis of Banking Industry Intelligent Marketing Application Released
防止数据冒用的方法