pay.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. function goPay(param, success) {
  2. var url = "/dealer/pay/gateway";
  3. var sendOpt = {
  4. url: url,
  5. type: "GET",
  6. // 非常特殊的处理,GET带JSON参数 todo
  7. data: {param: JSON.stringify(param)},
  8. mask: "正在获取支付参数...",
  9. success: function (res) {
  10. let payload = res.payload
  11. if (res.result == 1) {
  12. if (res.payload.payUrl) {
  13. location.href = res.payload.payUrl;
  14. } else {
  15. function onBridgeReady() {
  16. // 由于微信window.WeixinJSBridge经常报错,再判断一次
  17. if (!window.WeixinJSBridge) {
  18. mui.toast("微信支付初始化失败,请重试");
  19. return;
  20. }
  21. window.WeixinJSBridge.invoke("getBrandWCPayRequest", {
  22. appId: res.para.appId,
  23. timeStamp: res.para.timeStamp,
  24. nonceStr: res.para.nonceStr,
  25. "package": res.para.package,
  26. signType: res.para.signType,
  27. paySign: res.para.paySign
  28. }, function (e) {
  29. if ("get_brand_wcpay_request:ok" == e.err_msg) {
  30. if (payload.golden) {
  31. console.log('wechat golden plan has ad.')
  32. return;
  33. }
  34. location.href = '/public/thirdReceipt.html?orderType=recharge&outTradeNo=' + payload.outTradeNo;
  35. } else if ("get_brand_wcpay_request:fail" == e.err_msg) {
  36. mui.toast("付款失败");
  37. }
  38. });
  39. }
  40. if (typeof window.WeixinJSBridge == "undefined") {
  41. if (document.addEventListener) {
  42. document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
  43. } else if (document.attachEvent) {
  44. document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
  45. document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
  46. }
  47. } else {
  48. onBridgeReady();
  49. }
  50. }
  51. } else {
  52. mui.toast(res.description);
  53. }
  54. }
  55. }
  56. sendRequest(sendOpt);
  57. }