Explorar o código

增加授权自己公众号支付

谢杰标 %!s(int64=2) %!d(string=hai) anos
pai
achega
5ddbb0c0d9
Modificáronse 6 ficheiros con 86 adicións e 79 borrados
  1. 1 1
      common/config.js
  2. 8 1
      common/httpList/system.js
  3. 1 1
      common/methodTool.js
  4. 30 14
      common/navTo.js
  5. 0 25
      pages/index/index.vue
  6. 46 37
      pages2/order/confirm_pay.vue

+ 1 - 1
common/config.js

@@ -7,7 +7,7 @@ const test = {
   appid: "wxd3c8ae80cf43a305",
 };
 const index = 0; // 测试环境
-// const index = 1 // 祥粤云学堂
+// const index = 1; // 祥粤云学堂
 // const index = 2 // 祥粤学堂
 // const index = 3 // 勘设云学堂
 // const index = 4 // 中正云学堂

+ 8 - 1
common/httpList/system.js

@@ -10,5 +10,12 @@ export default {
 			noToken: true
 		})
 	},
-	
+	getWxConfig(data) {
+		return myRequest({
+			url: '/app/common/wx/config',
+			method: 'get',
+			data: data,
+			noToken: true
+		})
+	},
 }

+ 1 - 1
common/methodTool.js

@@ -641,5 +641,5 @@ export default {
     let domain =
       /^([\w-]+\.)+((com)|(net)|(org)|(gov\.cn)|(info)|(cc)|(com\.cn)|(net\.cn)|(org\.cn)|(name)|(biz)|(tv)|(cn)|(mobi)|(name)|(sh)|(ac)|   (io)|(tw)|(com\.tw)|(hk)|(com\.hk)|(ws)|(travel)|(us)|(tm)|(la)|(me\.uk)|(org\.uk)|(ltd\.uk)|(plc\.uk)|(in)|(eu)|(it)|(jp))$/;
     return domain.test(str);
-  },
+  }
 };

+ 30 - 14
common/navTo.js

@@ -1,18 +1,34 @@
-const togo = function(url, data) {
-	url += (url.indexOf('?') < 0 ? '?' : '&') + param(data)
-	
-	uni.navigateTo({
-		url: url
-	})
-}
+const togo = function (url, data) {
+  url += (url.indexOf("?") < 0 ? "?" : "&") + param(data);
+
+  uni.navigateTo({
+    url: url,
+  });
+};
 
 export function param(data) {
-	let url = ''
-	for (var k in data) {
-		let value = data[k] !== undefined ? data[k] : ''
-		url += '&' + k + '=' + encodeURIComponent(value)
-	}
-	return url ? url.substring(1) : ''
+  let url = "";
+  for (var k in data) {
+    let value = data[k] !== undefined ? data[k] : "";
+    url += "&" + k + "=" + encodeURIComponent(value);
+  }
+  return url ? url.substring(1) : "";
+}
+
+export function getQueryString(name) {
+  const url = location.search; //获取url中"?"符后的字串
+  let theRequest = new Object();
+  if (url.indexOf("?") != -1) {
+    let str = url.substr(1);
+    let strs = str.split("&");
+    for (let i = 0; i < strs.length; i++) {
+      theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
+    }
+  }
+  if (name) {
+    return theRequest[name];
+  }
+  return theRequest;
 }
 
-export {togo}
+export { togo };

+ 0 - 25
pages/index/index.vue

@@ -446,31 +446,6 @@ export default {
     });
   },
   onShow() {
-    // #ifdef H5
-    // if (location.search) {
-    //   console.log("url值:", location.search);
-    //   let arrs = location.search.slice(1).split("&");
-    //   for (let i = 0; i < arrs.length; i++) {
-    //     this.optObj[arrs[i].split("=")[0]] = arrs[i].split("=")[1];
-    //   }
-    //   console.log("获取的optObj:", this.optObj);
-    //   uni.setStorageSync("h5_code", this.optObj.code);
-    //   this.OfficialLogin();
-    // } else {
-    //   // 没有code,就重定向到地址https://www.xyyxt.net?ask_type=h.xyyxt.net 去获取code,授权后就会把code带上然后访问域名
-    //   if (
-    //     !uni.getStorageSync("h5_code") &&
-    //     process.env.NODE_ENV !== "development"
-    //   ) {
-    //     location.replace(
-    //       "https://" +
-    //         window.location.host +
-    //         "/?ask_type=" +
-    //         window.location.host
-    //     );
-    //   }
-    // }
-    // #endif
     this.getInfo(); // 判断有没有关注公众号
     this.isClickOff(); //关注公众号,每天最多显示1次;当天学员关闭弹窗后,无需再显示
     uni.removeStorageSync("goPath");

+ 46 - 37
pages2/order/confirm_pay.vue

@@ -108,6 +108,7 @@
 
 <script>
 import { mapGetters } from "vuex";
+import { getQueryString } from "../../common/navTo";
 import ClassTimeTip from "../../components/common/ClassTimeTip.vue";
 export default {
   data() {
@@ -138,65 +139,65 @@ export default {
       fromCart: "",
       hasPaying: false,
       showConfirmButton: false,
-      totalPrice: 0,
       confirmText: "",
-      optObj: {},
     };
   },
   onPullDownRefresh() {},
   onLoad(option) {
-    let self = this;
     this.fromCart = option.fromCart;
-    let list = self.shoppingCartList;
     this.isBK = option.isBK;
-    for (let i = 0; i < list.length; i++) {
-      this.totalPrice += Number(list[i].standPrice);
-    }
   },
   onShow() {
     // #ifdef H5
-    if (location.search.includes("code")) {
-      let arrs = location.search.slice(1).split("&");
-      for (let i = 0; i < arrs.length; i++) {
-        this.optObj[arrs[i].split("=")[0]] = arrs[i].split("=")[1];
-      }
-      this.$store.commit("setShoppingCartList", {
-        shoppingCartList: uni.getStorageSync("shopList"),
-      });
-      uni.setStorageSync("h5_code", this.optObj.code);
-      this.OfficialLogin();
-    } else {
-      // 没有code,就重定向到地址https://www.xyyxt.net?ask_type=https://api.xyyxt.net/pages2/order/confirm_pay 去获取code,授权后就会把code带上然后访问域名
-      // ?fromCart=&code=061F5a1w3aolh03SLe1w3sMsCF4F5a16&state=STATE
-      this.$api.checkBindGzh().then((res) => {
-        if (!res.data.data && process.env.NODE_ENV !== "development") {
-          uni.setStorageSync("shopList", this.shoppingCartList);
-          location.replace(
-            "https://www.xyyxt.net/?ask_type=" +
-              window.location.host +
-              "/pages2/order/confirm_pay"
-          );
-        }
-      });
-    }
+    this.authorize();
     // #endif
   },
   methods: {
-    OfficialLogin() {
-      console.log(this.optObj,this.optObj.code, "上传code");
+    authorize() {
+      if (location.search.includes("code")) {
+        const code = getQueryString("code");
+        this.$store.commit("setShoppingCartList", {
+          shoppingCartList: uni.getStorageSync("shopList"),
+        });
+        uni.setStorageSync("h5_code", code);
+        this.OfficialLogin(code);
+      } else {
+        // 没有code,就重定向到地址https://www.xyyxt.net?ask_type=https://api.xyyxt.net/pages2/order/confirm_pay 去获取code,授权后就会把code带上然后访问域名
+        // ?fromCart=&code=061F5a1w3aolh03SLe1w3sMsCF4F5a16&state=STATE
+        this.$api.checkBindGzh().then((res) => {
+          if (!res.data.data && process.env.NODE_ENV !== "development") {
+            uni.setStorageSync("shopList", this.shoppingCartList);
+            const url = window.location.host + "/pages2/order/confirm_pay";
+            // 跳自己授权
+            if (this.config.gzhSelfLicense) {
+              this.$api.getWxConfig().then((res) => {
+                location.replace(
+                  `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${
+                    res.data.data.gzhAppId
+                  }&redirect_uri=${encodeURIComponent(
+                    "https://" + url
+                  )}&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect`
+                );
+              });
+            } else {
+              location.replace("https://www.xyyxt.net/?ask_type=" + url);
+            }
+          }
+        });
+      }
+    },
+    OfficialLogin(code) {
       this.$api
         .OfficialLogin({
-          code: this.optObj.code,
+          code,
         })
         .then((res) => {
-          console.log(res, "接口返回");
           if (res.data.code !== 200) {
             this.$u.toast(res.data.msg);
           }
         });
     },
     postOrder() {
-      console.log(12312312321);
       let list = this.shoppingCartList;
       for (let i = 0; i < list.length; i++) {
         let item = list[i];
@@ -440,7 +441,15 @@ export default {
     },
   },
   onReachBottom() {},
-  computed: { ...mapGetters(["userInfo", "shoppingCartList", "sac"]) },
+  computed: {
+    ...mapGetters(["userInfo", "shoppingCartList", "sac", "config"]),
+    totalPrice() {
+      return this.shoppingCartList.reduce(
+        (a, b) => a + Number(b.standPrice),
+        0
+      );
+    },
+  },
   components: { ClassTimeTip },
 };
 </script>