Ver Fonte

获取手机号

shish há 4 dias atrás
pai
commit
cfbbff0597

+ 7 - 0
mallApp/src/api/mini/index.js

@@ -21,6 +21,13 @@ export const getWxPhone = data => {
 	return https.post('/user/mini-mobile', data)
 }
 
+/** *
+ * 点击授权获取手机号 mini (新接口)
+ */
+export const getMiniMobile = data => {
+	return https.post('/user/get-mini-mobile', data)
+}
+
 //点击授权获取字典
 export const getDictionaries = data => {
 	return https.post('/console/init', data)

+ 8 - 20
mallApp/src/components/wangCg.vue

@@ -40,7 +40,7 @@
 </template>
 
 <script>
-import { getWxPhone } from "@/api/mini"
+import { getMiniMobile } from "@/api/mini"
 import { create } from "@/api/user"
 import store from '@/store'
 import { TOKEN_STORAGE_KEY } from "@/constant/storageKeys";
@@ -62,25 +62,13 @@ export default {
   methods: {
     getWxMobile(e) {
       let that = this
-      if (e.detail.errMsg === "getPhoneNumber:ok") {
-        let currentMiniOpenId = uni.getStorageSync('miniOpenId')
-        getWxPhone({ iv: e.detail.iv, encryptedData: e.detail.encryptedData, miniOpenId: currentMiniOpenId }).then(subRes => {
-            if(subRes.data && subRes.data.hasNoOpenId && subRes.data.hasNoOpenId == 1){
-              uni.showModal({
-                title: '提示',
-                content: '网络异常,请重试一次',
-                success: function (res) {
-                  if (res.confirm) {
-                    console.log('用户点击确定')
-                  }
-                }
-              })
-              return false
-            }
-            this.form.mobile = subRes.data.mobile
-            that.confirmFn()
-        })
-      } else {
+    if (e.detail.errMsg === "getPhoneNumber:ok") {
+      let code = e.detail.code
+      getMiniMobile({ code: code }).then(subRes => {
+        this.form.mobile = subRes.data.mobile
+        that.confirmFn()
+      })
+    } else {
         this.$msg("获取手机失败");
       }
     },

+ 8 - 20
mallApp/src/pages/login/index.vue

@@ -37,7 +37,7 @@
 <script>
 import TuiListCell from "@/components/plugin/list-cell"
 const form = require("@/utils/formValidation.js")
-import { getWxInfo, getWxPhone } from "@/api/mini"
+import { getWxInfo, getMiniMobile } from "@/api/mini"
 import { create } from "@/api/user"
 import store from '@/store'
 import { TOKEN_STORAGE_KEY } from "@/constant/storageKeys";
@@ -93,25 +93,13 @@ export default {
     },
     getWxMobile(e) {
       let that = this
-      if (e.detail.errMsg === "getPhoneNumber:ok") {
-        let currentMiniOpenId = uni.getStorageSync('miniOpenId')
-        getWxPhone({ iv: e.detail.iv, encryptedData: e.detail.encryptedData, miniOpenId: currentMiniOpenId }).then(subRes => {
-          if (subRes.data && subRes.data.hasNoOpenId && subRes.data.hasNoOpenId == 1) {
-            uni.showModal({
-              title: '提示',
-              content: '网络异常,请重试一次',
-              success: function (res) {
-                if (res.confirm) {
-                  console.log('用户点击确定')
-                }
-              }
-            })
-            return false
-          }
-          this.form.mobile = subRes.data.mobile
-          that.confirmFn()
-        })
-      } else {
+    if (e.detail.errMsg === "getPhoneNumber:ok") {
+      let code = e.detail.code
+      getMiniMobile({ code: code }).then(subRes => {
+        this.form.mobile = subRes.data.mobile
+        that.confirmFn()
+      })
+    } else {
         this.$msg("获取手机失败");
       }
     }