Silent пре 6 година
родитељ
комит
5e7fb112d6

+ 17 - 30
app/Http/Controllers/WeChat/ApiController.php

@@ -161,37 +161,24 @@ class ApiController extends Controller
         if(empty($request->input('id')) || empty($we_chat_user = WeChatUser::find($request->input('id')))) {
         if(empty($request->input('id')) || empty($we_chat_user = WeChatUser::find($request->input('id')))) {
             return response()->json(['status' => 'fail', 'info' => '找不到用户']);
             return response()->json(['status' => 'fail', 'info' => '找不到用户']);
         }
         }
-        if(empty($request->input('iv')) || empty($request->input('encryptedData'))) {
-            return response()->json(['status' => 'error', 'info' => '参数错误']);
-        }
-        $iv = $request->input('iv');
-        $encryptedData = $request->input('encryptedData');
-        $session_key = $we_chat_user->session_key;
-        $app = app('wechat.mini_program');
-
-
-        $info = $app->encryptor->decryptData($session_key, $iv, $encryptedData);
-        if(isset($info['purePhoneNumber'])) {
-            $student = Student::where('phone', $info['purePhoneNumber'])->first();
-            if(empty($student)) {
-                return response()->json(['status' => 'fail', 'info' => '找不到学员']);
-            }
-            $res = $student->update([
-                'open_id' => $we_chat_user->open_id,
-                'nickname' => $we_chat_user->nickname,
-                'gender' => $we_chat_user->gender,
-                'city' => $we_chat_user->city,
-                'province' => $we_chat_user->province,
-                'country' => $we_chat_user->country,
-                'avatar_url' => $we_chat_user->avatar_url
-            ]);
-            if(empty($res)) {
-                return response()->json(['status' => 'fail', 'info' => '数据更新失败']);
-            }
-            $data = ['id' => $student->id, 'nickname' => $student->nickname, 'avatar_url' => $student->avatar_url];
-            return response()->json(['status' => 'success', 'info' => '操作成功', 'data' => $data]);
+        if(empty($request->input('phone')) || empty($student = Student::where('phone', $request->input('phone'))->first())) {
+            return response()->json(['status' => 'error', 'info' => '找不到学员']);
+        }
+
+        $res = $student->update([
+            'open_id' => $we_chat_user->open_id,
+            'nickname' => $we_chat_user->nickname,
+            'gender' => $we_chat_user->gender,
+            'city' => $we_chat_user->city,
+            'province' => $we_chat_user->province,
+            'country' => $we_chat_user->country,
+            'avatar_url' => $we_chat_user->avatar_url
+        ]);
+        if(empty($res)) {
+            return response()->json(['status' => 'fail', 'info' => '数据更新失败']);
         }
         }
-        return response()->json(['status' => 'fail', 'info' => '没有绑定手机']);
+        $data = ['id' => $student->id, 'nickname' => $student->nickname, 'avatar_url' => $student->avatar_url];
+        return response()->json(['status' => 'success', 'info' => '操作成功', 'data' => $data]);
     }
     }
 
 
     public function checkPosition(Request $request)
     public function checkPosition(Request $request)

+ 22 - 5
wechat/pages/bind-phone/index.js

@@ -14,14 +14,31 @@ Page({
    * 生命周期函数--监听页面加载
    * 生命周期函数--监听页面加载
    */
    */
   onLoad: function (options) {
   onLoad: function (options) {
-  
+    
+  },
+  handleFieldChange: function(e) {
+    console.log(this.data.phone)
+    console.log(e)
   },
   },
 
 
   formSubmit: e => {
   formSubmit: e => {
-    console.log(e)
+    if(!e.detail.value.phone) {
+      wx.showToast({
+        title: '手机号不能为空',
+      })
+
+      // wx.request({
+      //   url: api.bindPhoneUrl,
+      //   method: 'GET',
+      //   data: {
+      //     'id': wx.getStorageSync('we_chat_user_id'),
+      //     'phone': e.detail.value.phone
+      //   }
+      // })
+    }
   },
   },
 
 
-  getPhoneNumber: e => {
+  getPhoneNumber: function(e) {
     var that = this;
     var that = this;
     if (e.detail.errMsg == 'getPhoneNumber:ok') {
     if (e.detail.errMsg == 'getPhoneNumber:ok') {
       wx.request({
       wx.request({
@@ -33,9 +50,10 @@ Page({
           'encryptedData': e.detail.encryptedData,
           'encryptedData': e.detail.encryptedData,
         },
         },
         success: res => {
         success: res => {
+          console.log(res)
           if(res.data.status == 'success') {
           if(res.data.status == 'success') {
             that.setData({
             that.setData({
-              'phone': res.data.phone
+              phone: res.data.phone
             })
             })
           } else if(res.data.status == 'fail') {
           } else if(res.data.status == 'fail') {
             wx.showToast({
             wx.showToast({
@@ -45,7 +63,6 @@ Page({
         }
         }
       })
       })
     }
     }
-    console.log(e)
   },
   },
 
 
   /**
   /**

+ 1 - 1
wechat/pages/bind-phone/index.wxml

@@ -13,7 +13,7 @@
     <zan-row>
     <zan-row>
       <view class='sg-row'>
       <view class='sg-row'>
         <zan-col col="16" col-class="custom-zan-col">
         <zan-col col="16" col-class="custom-zan-col">
-          <zan-field placeholder="输入手机号" focus="true" name='phone' value='{{ phone }}'></zan-field>
+          <zan-field placeholder="输入手机号" focus="true" name='phone' value='{{ phone }}' bind:change="handleFieldChange"></zan-field>
         </zan-col>
         </zan-col>
         <zan-col col="8" col-class="custom-zan-col">
         <zan-col col="8" col-class="custom-zan-col">
           <zan-button type='warn' openType="getPhoneNumber" class='get-phone-btn' bindgetphonenumber='getPhoneNumber'>获取</zan-button>
           <zan-button type='warn' openType="getPhoneNumber" class='get-phone-btn' bindgetphonenumber='getPhoneNumber'>获取</zan-button>

+ 1 - 0
wechat/utils/api.js

@@ -17,4 +17,5 @@ module.exports = {
   getAnnouncesUrl: headUrl + 'getAnnounces',
   getAnnouncesUrl: headUrl + 'getAnnounces',
   updateUserInfoUrl: headUrl + 'updateUserInfo',
   updateUserInfoUrl: headUrl + 'updateUserInfo',
   bindPhoneUrl: headUrl + 'bindPhone',
   bindPhoneUrl: headUrl + 'bindPhone',
+  getPhoneUrl: headUrl + 'getPhone',
 }
 }