在做公众号商城的时候,需要用到调用微信支付,这是微信官方文档教程

https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=7_7&index=6,详细描述了怎么调起微信支付,以下代码是我的实际业务调用微信支付完整流程

到订单页面点击提交订单按钮,此时点击事件先向后台发个请求,公司的后端人员通过代码去对接微信的系统,生成一个预订单,然后返回一个prepay_id,具体可以看官方文档里边的业务流程图。在我们刚才向接口发送请求以后,后端会把信息返回给我们,包括appId、timeStamp、nonceStr、package、signType这个值。这些值都是我们调起微信支付必须的。

代码如下:

            this.getFetch("公司后端提供的接口", data).then(res => {
if (res.data.code * 1 === 1) {
function onBridgeReady() {
WeixinJSBridge.invoke(
"getBrandWCPayRequest", {
appId: res.data.data.jsApiId, //公众号名称,由商户传入
timeStamp:res.data.data.timestamp, //时间戳,自1970年以来的秒数
nonceStr: res.data.data.nonceStr, //随机串
package: res.data.data.package,
signType: res.data.data.signType, //微信签名方式:
paySign: res.data.data.paySign //微信签名
},
wxResponse => {
if (wxResponse.err_msg == "get_brand_wcpay_request:ok") {
window.location.href = window.location.origin + "/couponPaySuccess?ordernum=" + res.data.data.id;
}
if (wxResponse.err_msg == "get_brand_wcpay_request:fail") {
_this.$toast("支付失败");
}
if (wxResponse.err_msg == "get_brand_wcpay_request:cancel") {
_this.$toast("支付取消");
}
}
);
}
if (typeof WeixinJSBridge == "undefined") {
if (document.addEventListener) {
document.addEventListener(
"WeixinJSBridgeReady",
onBridgeReady,
false
);
} else if (document.attachEvent) {
document.attachEvent("WeixinJSBridgeReady", onBridgeReady);
document.attachEvent(
"onWeixinJSBridgeReady",
onBridgeReady
);
}
} else {
onBridgeReady();
}
} else if (res.data.code * 1 === -1) {
this.autoLogin();
} else {
this.$toast(res.data.msg);
this.wxBtn=true;
} });

最新文章

  1. customErrors与错误页面
  2. iOS开发 适配iOS10以及Xcode8[转]
  3. EF事务嵌套
  4. Python开发入门与实战15-IIS部署
  5. Nginx-->基础-->排错-->nginx错误总结
  6. ERWin 7.2下载安装及注册机
  7. span width无效
  8. jQuery对表单、表格的操作及更多应用(下:其他应用)
  9. ubuntu下ssh登陆阿里云服务器(ubuntu系统)中文乱码问题
  10. 【多端应用开发系列0.0.0——之总序】xy多端应用开发方案定制
  11. 《python基础教程》笔记之 其它语句1
  12. 在jsp提交表单的参数封装到一个方法里
  13. python键盘读入的input方法
  14. uoj123 【NOI2013】小Q的修炼
  15. JavaScript之简易http接口测试工具网页版
  16. maven项目板块的pom.xml配置
  17. Testing - 软件测试的思维和技巧
  18. 如何在命令长度受限的情况下成功get到webshell(函数参数受限突破、mysql的骚操作)
  19. ng4.0 使用[innerHTML]动态插入的富文本如何设置样式
  20. Linux CentOS 7 安装mongoDB(4.0.6)

热门文章

  1. [IOI2016] shortcut
  2. 单例 pickle模块
  3. 加速 Document AI (文档智能) 发展
  4. DVWA靶场实战(十)——XSS(DOM)
  5. linux/windows解决/关闭端口占用
  6. Dijkstra算法详解(朴素算法+堆优化)
  7. Node.js学习笔记----day05 (Promise详情)
  8. 11月30日内容总结——前端简介、http协议概念、html协议概念及基础知识和部分标签的讲解
  9. 2.2.vue用法在uniapp中的使用_
  10. Zookeeper+SpringCloud微服务(入门二)