Wxa Pay

Brightcells 6 years ago
parent
commit
74612b468f
2 changed files with 45 additions and 19 deletions
  1. 42 19
      page/templates/page/mini_preview2.html
  2. 3 0
      pai2/urls.py

+ 42 - 19
page/templates/page/mini_preview2.html

@@ -186,6 +186,7 @@
186 186
 <script src="//cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
187 187
 <script src="//cdn.bootcss.com/photoswipe/4.1.2/photoswipe.min.js"></script>
188 188
 <script src="//cdn.bootcss.com/photoswipe/4.1.2/photoswipe-ui-default.min.js"></script>
189
+<script type="text/javascript" src="//res.wx.qq.com/open/js/jweixin-1.3.2.js"></script>
189 190
 <script>
190 191
     $(function () {
191 192
         /** 格式化输入字符串 **/
@@ -984,6 +985,7 @@
984 985
         var leftImgs = '';
985 986
         var rightImgs = '';
986 987
         var swipeItems = [];
988
+        var swipePhotos = [];
987 989
         var curIdx = -1;
988 990
 
989 991
         for (var i = 0; i < session_photos.length; i++) {
@@ -1018,6 +1020,7 @@
1018 1020
                     w: photos[j].photo_w,
1019 1021
                     h: photos[j].photo_h,
1020 1022
                 })
1023
+                swipePhotos.push(photos[j]);
1021 1024
                 photoIdx += 1;
1022 1025
             }
1023 1026
         }
@@ -1036,8 +1039,9 @@
1036 1039
             tapToClose: true,
1037 1040
         };
1038 1041
 
1039
-        function buyornot() {
1042
+        function displayornot() {
1040 1043
             $('#buy').show();
1044
+            $('#mask-thump').show();
1041 1045
         }
1042 1046
 
1043 1047
         // Initializes and opens PhotoSwipe
@@ -1047,15 +1051,15 @@
1047 1051
             var gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, swipeItems, options);
1048 1052
             gallery.init();
1049 1053
 
1050
-            buyornot();
1051
-            $('#mask-thump').show();
1054
+            displayornot();
1055
+
1052 1056
 
1053 1057
             // After slides change
1054 1058
             // (after content changed)
1055 1059
             gallery.listen('afterChange', function() {
1056
-                console.log(gallery.getCurrentIndex())
1060
+                console.log(gallery.getCurrentIndex());
1057 1061
                 curIdx = gallery.getCurrentIndex();
1058
-                buyornot()
1062
+                displayornot()
1059 1063
             });
1060 1064
 
1061 1065
             // Gallery starts closing
@@ -1064,23 +1068,42 @@
1064 1068
                 $('#mask-thump').hide();
1065 1069
             });
1066 1070
         })
1067
-        
1071
+
1068 1072
         $('#nomark').click(function () {
1069
-            
1073
+            var photoInfo = swipePhotos[curIdx];
1074
+
1075
+            $.ajax({
1076
+                url: '/mini/order_create',
1077
+                type: 'POST',
1078
+                data: {
1079
+                    group_id: photoInfo.group_id,
1080
+                    user_id: photoInfo.user_id,
1081
+                    photo_id: photoInfo.photo_id,
1082
+                    photo_type: 'nomark',
1083
+                    body: '去除水印',
1084
+                    total_fee: 1,
1085
+                    trade_type: 'MINIAPP',
1086
+                },
1087
+                timeout: 5000,
1088
+                cache: true,
1089
+                success: function (res) {
1090
+                    if (res.status == 200) {
1091
+                        var order_id = res.data.order_id;
1092
+                        //点击微信支付后,调取统一下单接口生成微信小程序支付需要的支付参数
1093
+                        var params = '?timeStamp=' + res.data.timeStamp + '&nonceStr=' + res.data.nonceStr
1094
+                                + '&package=' + res.data.package.split("=")[1] + '&signType=MD5'
1095
+                                + '&paySign=' + res.data.paySign;
1096
+                        //定义path 与小程序的支付页面的路径相对应
1097
+                        var path = '/pages/wxpay/wxpay' + params;
1098
+                        //通过JSSDK的api使小程序跳转到指定的小程序页面
1099
+                        wx.miniProgram.navigateTo({url: path});
1100
+                    }
1101
+                },
1102
+                error: function (res) {
1103
+                }
1104
+            });
1070 1105
         })
1071 1106
     })
1072 1107
 </script>
1073
-<script type="text/javascript" src="//res.wx.qq.com/open/js/jweixin-1.3.2.js"></script>
1074
-<script type="text/javascript" src="{% static 'pai2/js/jswe-0.0.4.js' %}"></script>
1075
-<script>
1076
-    V.initWxData({
1077
-        imgUrl: "http://pai.ai/static/pai2/img/paiai_96_96.png",
1078
-        link: 'http://pai.ai/w/o?r=http%3A%2F%2Fpai.ai%2Fp%2Floginqr',
1079
-        desc: "授权登录",
1080
-        title: "授权登录",
1081
-        timeLine: ""
1082
-    }, true);
1083
-    V.hideOptionMenu();
1084
-</script>
1085 1108
 </body>
1086 1109
 </html>

+ 3 - 0
pai2/urls.py

@@ -24,6 +24,7 @@ from rest_framework import routers
24 24
 from account import account_views
25 25
 from group import group_views, grouppage_views
26 26
 from miniapp import views as mini_views
27
+from pay import views as pay_views
27 28
 from photo import views as photo_views
28 29
 from website import views as website_views
29 30
 
@@ -77,6 +78,8 @@ urlpatterns += [
77 78
 # Mini App
78 79
 urlpatterns += [
79 80
     url(r'^mini/userinfo$', mini_views.get_userinfo_api, name='get_userinfo_api2'),  # 获取用户信息
81
+    url(r'^mini/order_create$', pay_views.wx_order_create_api, name='wx_order_create_api'),  # 订单创建
82
+    url(r'^mini/order_query$', pay_views.wx_order_query_api, name='wx_order_query_api'),  # 订单查询补单
80 83
 ]
81 84
 
82 85
 # Wire up our API using automatic URL routing.