wechatPay.blade.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8"/>
  5. <meta name="viewport"
  6. content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  7. <title>微信支付</title>
  8. </head>
  9. <body>
  10. @if(!$success)
  11. <div style="color: red;text-align: center;margin-top: 20px;">
  12. {{$msg}}
  13. </div>
  14. @else
  15. <script src="https://res.wx.qq.com/open/js/jweixin-1.4.0.js"></script>
  16. <script type="text/javascript" charset="utf-8">
  17. wx.config({!! $configStr !!});
  18. wx.ready(function () {
  19. wx.chooseWXPay({
  20. timestamp: {{$prepayConfig['timestamp']}},
  21. nonceStr: '{{$prepayConfig['nonceStr']}}',
  22. package: '{{$prepayConfig['package']}}',
  23. signType: '{{$prepayConfig['signType']}}',
  24. paySign: '{{$prepayConfig['paySign']}}', // 支付签名
  25. success: res => {
  26. // 支付成功
  27. if (res.errMsg === "chooseWXPay:ok") {
  28. // 使用以上方式判断前端返回,微信团队郑重提示:
  29. //res.err_msg将在用户支付成功后返回ok,但并不保证它绝对可靠。
  30. // that.payCheckSuccess(); // 支付成功回调
  31. WeixinJSBridge.call('closeWindow');
  32. } else if (res.errMsg === "chooseWXPay:cancel") {
  33. console.log('支付已取消!')
  34. WeixinJSBridge.call('closeWindow');
  35. } else {
  36. console.log('其他错误')
  37. }
  38. },
  39. fail: res => {
  40. console.log(JSON.stringify(res));
  41. alert(JSON.stringify(res))
  42. }
  43. });
  44. });
  45. wx.error(res => {
  46. console.log(JSON.stringify(res));
  47. alert(JSON.stringify(res))
  48. });
  49. </script>
  50. @endif
  51. </body>
  52. </html>