luck 2 anni fa
parent
commit
b1f348343e

+ 7 - 2
app.js

@@ -80,14 +80,15 @@ App({
   login(lat="",lng=""){
     var that=this;
    return new Promise((resolve,reject)=>{
-
+    console.log(3333333)
     wx.checkSession({
       success: (res) => {
-
+        console.log(444444)
       },
       fail:(res)=>{
         wx.login({
           success: res => {
+          console.log(res)
             // 发送 res.code 到后台换取 openId, sessionKey, unionId
             that.api.useApi(that.globalData.baseAppUrl+"api/login",{
               code:res.code,
@@ -104,6 +105,10 @@ App({
                 },1000);
               }else{
                 wx.hideLoading();
+                wx.setStorageSync('token', res.message.token);
+                wx.setStorageSync('uid', res.message.user_id);
+                wx.setStorageSync('seisson_key', res.message.session_key);
+                wx.setStorageSync('nid', res.message.network_id);//当前网点选择id
                 resolve(res);
               }
           

+ 6 - 0
cloudfunction/getPhoneNumber/config.json

@@ -0,0 +1,6 @@
+{
+  "permissions": {
+    "openapi": [
+    ]
+  }
+}

+ 65 - 0
cloudfunction/getPhoneNumber/index.js

@@ -0,0 +1,65 @@
+// 云函数入口文件
+const cloud = require('wx-server-sdk')
+const request = require('request');
+
+cloud.init()
+
+// 云函数入口函数
+exports.main = async (event, context) => {
+  const wxContext = cloud.getWXContext()
+
+  var data=event.message;
+
+  return new Promise((resolve, reject) => {
+    try {
+      request({
+        method: 'POST',
+        headers: {
+          Authorization: event.message.token || '',
+          "content-type": "application/json",
+        },
+        body: JSON.stringify(data),
+        url: 'https://wash.nanodreamtech.com/api/user/getPhoneNumber',
+      }, function (error, response, body) {
+        if (error) {
+          return reject(error);
+        }
+        return resolve(JSON.parse(body));
+      })
+    } catch (e) {
+      return reject(e)
+    }
+  });
+
+}
+
+
+
+
+
+
+
+
+
+
+
+  // request({
+  //   url: 'https://wash.nanodreamtech.com/api/user/getPhoneNumber', // 云端正式服
+  //   body:data,
+  //   method:'POST',
+  //   headers: {
+  //       Authorization: event.message.token || '',
+  //       'content-type': 'application/json',
+  //   },
+  //   json: true, // 添加这个配置
+  //   },function (error,response,body){
+  //     if(!error&&response.statusCode==200){
+  //       return body
+  //     }
+        
+  //   })
+
+
+
+ 
+

+ 14 - 0
cloudfunction/getPhoneNumber/package.json

@@ -0,0 +1,14 @@
+{
+  "name": "get",
+  "version": "1.0.0",
+  "description": "",
+  "main": "index.js",
+  "scripts": {
+    "test": "echo \"Error: no test specified\" && exit 1"
+  },
+  "author": "",
+  "license": "ISC",
+  "dependencies": {
+    "wx-server-sdk": "~2.5.3"
+  }
+}

+ 23 - 7
pages/order/confirmOreder/confirmOreder.js

@@ -82,18 +82,34 @@ Page({
         })
     },
     getPhoneNumber (e){
-        app.login()
+        app.login();
         console.log(e)
-        this.setData({
-            code: e.detail.code,
-          })
-
+        
+            var data={
+                'mds':wx.getStorageSync('seisson_key'),
+                'encryptedData':e.detail.encryptedData,
+                'errMsg':e.detail.errMsg,
+                'iv':e.detail.iv,
+                'appid':wx.getAppBaseInfo().host.appId,
+                'token':wx.getStorageSync('token')
+            }
              wx.cloud.callFunction({
               name: 'getPhoneNumber',
               data:{
-                  message:e.detail
+                  'message':data
               },
-              success:res=>{console.log(res)},
+              success:res=>{
+                  console.log(res)
+            var par=res.result.original;
+                  if(par.code==200){
+                    var phone=par.message.data.phone
+                    if(phone){
+                        this.setData({
+                            code: phone,
+                          })     
+                    }
+                  }
+            },
               fail:err=>{
                   console.log(err)
               }