vue3微信支付和支付宝支付

// 判断是否为微信内置浏览器
let browser: any = navigator.userAgent.toLowerCase();
let isWechat: any = browser.match(/MicroMessenger/i) == "micromessenger";
// 支付宝支付
if (gather.pay_type == 2) {
orderPay({
pay_type: pay_typeA,
order_sn: order_snA,
gateway: gatewayA,
wap_return_url: wap_return_urlA,
}).then((res: any) => {
if (res.code == 0) {
aliPay(res);
}
});
} else {
// 微信支付
if (!localStorage.OPENID && route.query.openid) {
localStorage.OPENID = route.query.openid;
}
gather.openid = isWechat ? localStorage.OPENID : "";
if (isWechat && !localStorage.OPENID) {
// 获取openid
let url =
window.location.origin +
"/get_wx_info?url=" +
encodeURIComponent(window.location.href);
window.location.href = url;
} else {
orderPay({
pay_type: pay_typeA,
order_sn: order_snA,
gateway: gatewayA,
wap_return_url: wap_return_urlA,
open_id: gather.openid,
}).then((res: any) => {
if (res) {
// 微信H5
if (!isWechat) {
window.location.href =
res.data.option.mweb_url + wap_return_urlA;
return;
} else {
// 微信内置
wechatPay(res.data.option);
}
}
});
}
} const wechatPay = (result: object): void => {
//封装请求微信支付接口数据
var request_data = {
appId: (result as any).appId,
timeStamp: (result as any).timeStamp + "",
nonceStr: (result as any).nonceStr,
package: (result as any).package,
signType: "MD5",
paySign: (result as any).paySign,
};
if (typeof (window as any).WeixinJSBridge == "undefined") {
if ((document as any).addEventListener) {
(document as any).addEventListener(
"WeixinJSBridgeReady",
onBridgeReady(request_data),
false
);
} else if ((document as any).attachEvent) {
(document as any).attachEvent(
"WeixinJSBridgeReady",
onBridgeReady(request_data)
);
(document as any).attachEvent(
"OnWeixinJSBridgeReady",
onBridgeReady(request_data)
);
}
} else {
onBridgeReady(request_data);
}
};
//微信方法
const onBridgeReady = (request_data: object): void => {
(window as any).WeixinJSBridge.invoke(
"getBrandWCPayRequest",
request_data,
(res: any) => {
if (res.err_msg == "get_brand_wcpay_request:ok") {
Notify({ type: "success", message: "支付成功" });
router.push({
path: "/mineSubject",
});
} else if (res.err_msg == "get_brand_wcpay_request:cancel") {
} else if (res.err_msg == "get_brand_wcpay_request:fail") {
}
}
);
};
支付宝支付方法

const aliPay = (res:any)=>{
const div = document.createElement('div');
div.innerHTML = res.data.option; //res.data是返回的表单
console.log('res.option',res.data.option); document.body.appendChild(div);
(document as any).forms.alipaysubmit.submit();
}

最新文章

  1. 第五章GPIO接口
  2. jquery总结05-常用事件02-表单事件
  3. C#与数据库访问技术总结(十六)之 DataSet对象
  4. CollectionView添加头尾部
  5. [Arduino] Arduino Uno R3 中文介绍
  6. 1026: [SCOI2009]windy数 - BZOJ
  7. 第1章 网络编程基础(3)——基本Socket通信
  8. 用于防SQL注入的几个函数
  9. Javascript高级程序设计读书笔记(第三章)
  10. POJ 2538 WERTYU水的问题
  11. 2014年百度之星程序设计大赛 - 资格赛 1002 Disk Schedule(双调欧几里得旅行商问题)
  12. 转:【Java并发编程】之十:使用wait/notify/notifyAll实现线程间通信的几点重要说明
  13. Storm知识点笔记
  14. JMX,Jstatd做好JVM应用上线的最后一层保障
  15. chrome浏览器安装不上的惨痛经历
  16. MySQL 从库down机
  17. 在线linux 平台
  18. 20172325 2017-2018-2 《Java程序设计》第七周学习总结
  19. find bugs设置
  20. iview-cli 项目、iView admin 代理与跨域问题解决方案

热门文章

  1. CCIE DC Multicast Part 3.
  2. 第二性 合卷本 横本.EPUB
  3. el-tree 点击父级或者父级的checkbox,展开所有子集
  4. Amd,Cmd, Commonjs, ES6 import/export的异同点
  5. 最简spring IOC实现
  6. Lombok Requires Annotation Processing
  7. Postman中添加多个Cookie
  8. Linux系统root密码忘记修改
  9. J V M大概理解
  10. 说说Selenium的几个痛处