pay_wx_two.blade.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <!DOCTYPE html>
  2. <html class="bg-white">
  3. <head>
  4. <meta charset="utf-8">
  5. <!--此行代码为禁止苹果手机自动识别电话号码-->
  6. <meta name="format-detection" content="telephone=no">
  7. <meta name="viewport"
  8. content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,initial-scale=1.0,width=device-width"/>
  9. <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
  10. <title>{{$shop_info['shop_name']}}支付</title>
  11. <link rel="stylesheet" type="text/css" href="{{asset('wap/css/weui.min.css')}}"/>
  12. <link rel="stylesheet" type="text/css" href="{{asset('wap/css/common.css')}}"/>
  13. <link rel="stylesheet" type="text/css" href="{{asset('wap/css/pay-page.css')}}"/>
  14. <script src="{{asset('wap/js/jquery-2.1.4.js')}}"></script>
  15. <script src="{{asset('wap/js/vue.js')}}?a=1"></script>
  16. <script src="{{asset('wap/js/jweixin-1.6.0.js')}}?a=1"></script>
  17. <script src="{{asset('wap/js/common.js')}}?a=1"></script>
  18. </head>
  19. <body>
  20. <div id="app">
  21. <!-- 导航栏 -->
  22. <div class="nav-bar">
  23. <div class="nav-title">{{$shop_info['shop_name']}}</div>
  24. </div>
  25. <!-- 支付详情 -->
  26. <div class="pay-detail">
  27. <form id="zfb_pay" method="post" action="{{route('pay.zfb_pay')}}">
  28. <div class="pay-layout">
  29. <div class="spend-total">消费总额</div>
  30. <div class="input-money">
  31. <span>¥</span>
  32. <input type="number" v-model="pay_money" mix="0.01" ref="textarea" :autofocus="true"
  33. style="width: 90%">
  34. </div>
  35. <input type="hidden" name="shop_id" value="{{$shop_info['id']}}"></input>
  36. <div class="prompt">可询问工作人员应缴费用总额</div>
  37. </div>
  38. </form>
  39. </div>
  40. <!-- button -->
  41. <div class="button-layout" @click="creatWxPay">
  42. <div class="button">
  43. <span>支付</span>
  44. </div>
  45. </div>
  46. <!--BEGIN toast-->
  47. <div id="toast" style="display: none;">
  48. <div class="weui-mask_transparent"></div>
  49. <div class="weui-toast">
  50. <i class="weui-icon-success-no-circle weui-icon_toast"></i>
  51. <p class="weui-toast__content">@{{success_msg}}</p>
  52. </div>
  53. </div>
  54. <!--BEGIN toast-->
  55. <div id="textMoreToast" v-show="error_show">
  56. <div class="weui-mask_transparent"></div>
  57. <div class="weui-toast weui-toast_text-more">
  58. <i class="weui-icon-warn weui-icon_toast"></i>
  59. <p class="weui-toast__content">@{{error_msg}}</p>
  60. </div>
  61. </div>
  62. </div>
  63. <script>
  64. $(function () {
  65. var vm = new Vue({
  66. el: '#app',
  67. data: {
  68. pay_money: '',
  69. success_msg: '',
  70. error_msg: '',
  71. error_show: false,
  72. success_show: false,
  73. is_pay: false,
  74. is_ajax: false,
  75. wx_config: {
  76. debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
  77. appId: "{{$wx_js['appid']}}", // 必填,公众号的唯一标识
  78. timestamp: {{$wx_js['timestamp']}}, // 必填,生成签名的时间戳
  79. nonceStr: "{{$wx_js['noncestr']}}", // 必填,生成签名的随机串
  80. signature: "{{$wx_js['signature']}}",// 必填,签名
  81. jsApiList: ['chooseWXPay'] // 必填,需要使用的JS接口列表
  82. },
  83. defaultHeight: '0', //默认屏幕高度
  84. nowHeight: '0', //实时屏幕高度
  85. },
  86. mounted() {
  87. //获取默认高度
  88. },
  89. methods: {
  90. 'errorMgs': function (error_msg) {
  91. this.error_msg = error_msg;
  92. this.error_show = true;
  93. setTimeout(function () {
  94. vm.error_show = false;
  95. }, 2000)
  96. },
  97. 'successMsg': function (success_msg) {
  98. this.success_msg = success_msg;
  99. this.success_show = true;
  100. setTimeout(function () {
  101. vm.success_show = false;
  102. }, 2000)
  103. },
  104. 'startWx': function () {
  105. wx.config(this.wx_config);
  106. wx.error(function (res) {
  107. // config信息验证失败会执行error函数,如签名过期导致验证失败,具体错误信息可以打开config的debug模式查看,也可以在返回的res参数中查看,对于SPA可以在这里更新签名。
  108. console.log(res);
  109. });
  110. },
  111. 'creatWxPay': function () {
  112. if (this.is_ajax) {
  113. return false;
  114. }
  115. // this.is_ajax = true;
  116. let _that = this;
  117. sendAjax('{{route('pay.wx_pay')}}', {
  118. 'pay_money': this.pay_money,
  119. 'shop_id': '{{$shop_info['id']}}'
  120. }, function (data) {
  121. if (data.code * 1 == 1) {
  122. // return false;
  123. wx.chooseWXPay({
  124. timestamp: data.data.timeStamp, // 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
  125. nonceStr: data.data.nonceStr, // 支付签名随机串,不长于 32 位
  126. package: data.data.package, // 统一支付接口返回的prepay_id参数值,提交格式如:prepay_id=\*\*\*)
  127. signType: data.data.signType, // 微信支付V3的传入RSA,微信支付V2的传入格式与V2统一下单的签名格式保持一致
  128. paySign: data.data.paySign, // 支付签名
  129. success: function (res) {
  130. // 支付成功后的回调函数
  131. _that.successMsg('支付成功');
  132. setTimeout(function () {
  133. window.location.href = '{{route('pay.pay_end')}}?pay_id=' + data.data.order_id;
  134. }, 1500);
  135. }
  136. });
  137. } else {
  138. vm.is_ajax = false;
  139. vm.errorMgs(data.msg);
  140. }
  141. })
  142. }
  143. },
  144. watch: {
  145. 'pay_money': function () {
  146. if (this.pay_money * 1 == 0) {
  147. this.is_pay = false;
  148. return false;
  149. }
  150. if (this.pay_money != '') {
  151. if (isNaN(this.pay_money) || this.pay_money * 1 < 0) {
  152. this.is_pay = false;
  153. this.pay_money = '';
  154. this.errorMgs('支付金额不合法');
  155. return false;
  156. }
  157. if (this.pay_money * 1 < 0.01) {
  158. this.is_pay = false;
  159. this.errorMgs('最低支付金额0.01元');
  160. return false;
  161. }
  162. }
  163. this.is_pay = true;
  164. }
  165. },
  166. created: function () {
  167. console.log('------------------')
  168. this.startWx();
  169. }
  170. });
  171. })
  172. </script>
  173. </body>
  174. </html>