Silent 6 年之前
父节点
当前提交
517b975645

+ 18 - 0
app/Http/Controllers/WeChat/ApiController.php

xqd
@@ -135,6 +135,24 @@ class ApiController extends Controller
         return response()->json(['status' => 'success', 'info' => '操作成功', 'data' => $data]);
     }
 
+    public function bindPhone(Request $request)
+    {
+        if(empty($request->input('id')) || empty($we_chat_user = WeChatUser::find($request->input('id')))) {
+            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);
+        Log::info($info);
+    }
+
     public function checkPosition(Request $request)
     {
         if(empty($request->input('latitude')) || empty($request->input('longitude'))) {

+ 2 - 1
routes/wechat.php

xqd
@@ -15,4 +15,5 @@ Route::get('getRemarkTitles', 'ApiController@getRemarkTitles');
 Route::get('remarkTeacher', 'ApiController@remarkTeacher');
 Route::get('getArticleContent', 'ApiController@getArticleContent');
 Route::get('getAnnounces', 'ApiController@getAnnounces');
-Route::post('updateUserInfo', 'ApiController@updateUserInfo');
+Route::post('updateUserInfo', 'ApiController@updateUserInfo');
+Route::post('bindPhone', 'ApiController@bindPhone');

+ 9 - 0
wechat/pages/bind-phone/index.js

xqd
@@ -15,6 +15,15 @@ Page({
   
   },
 
+  getPhoneNumber: e => {
+    if (e.detail.errMsg == 'getPhoneNumber:ok') {
+      wx.request({
+        url: 'updateUserPhone',
+      })
+    }
+    console.log(e)
+  },
+
   /**
    * 生命周期函数--监听页面初次渲染完成
    */

+ 4 - 4
wechat/pages/bind-phone/index.json

xqd
@@ -3,10 +3,10 @@
   "navigationBarTextStyle": "white",
   "navigationBarTitleText": "钢琴时间",
   "usingComponents": {
-    "zan-button": "/bower_components/zanui-weapp/dist/btn/index",
-    "zan-button-group": "/bower_components/zanui-weapp/dist/btn-group/index",
-    "zan-row": "/bower_components/zanui-weapp/dist/row/index",
-    "zan-col": "/bower_components/zanui-weapp/dist/col/index",
+    "zan-button": "../../bower_components/zanui-weapp/dist/btn/index",
+    "zan-button-group": "../../bower_components/zanui-weapp/dist/btn-group/index",
+    "zan-row": "../../bower_components/zanui-weapp/dist/row/index",
+    "zan-col": "../../bower_components/zanui-weapp/dist/col/index",
     "zan-popup": "../../bower_components/zanui-weapp/dist/popup/index",
     "zan-field": "../../bower_components/zanui-weapp/dist/field/index"
   }

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

xqd xqd xqd
@@ -1,10 +1,10 @@
 <!--pages/bind-phone/index.wxml-->
-<view class='login-container'>
+<view class='bind-phone-container'>
   <form bindsubmit="formSubmit">
     <zan-row>
       <view class='sg-row'>
-        <view class='login-avatar-container'>
-          <view class='login-avatar-wrapper'>
+        <view class='bind-phone-avatar-container'>
+          <view class='bind-phone-avatar-wrapper'>
             <open-data type='userAvatarUrl' class='wxAvatarUrl'></open-data>
           </view>
         </view>
@@ -13,7 +13,7 @@
     <zan-row>
       <view class='sg-row'>
         <zan-col col="16" col-class="custom-zan-col">
-          <zan-field placeholder="输入手机号" focus="true" name='phone' bind:blur="getPhoneInput"></zan-field>
+          <zan-field placeholder="输入手机号" focus="true" name='phone'></zan-field>
         </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>
@@ -21,7 +21,7 @@
       </view>
     </zan-row>
     <view class="btn-area">
-      <button formType="submit" type='primary' class='login-btn'>登录</button>
+      <button formType="submit" type='primary' class='bind-phone-btn'>绑定手机号</button>
     </view>
   </form>
 </view>

+ 4 - 4
wechat/pages/bind-phone/index.wxss

xqd
@@ -5,23 +5,23 @@
 .btn-area {
   margin: 20px 0;
 }
-.login-avatar-wrapper {
+.bind-phone-avatar-wrapper {
   width: 65px;
   height: 65px;
   border-radius: 50px;
   overflow:hidden;
   border:3px #e3e3e3 solid;
 }
-.login-avatar-container {
+.bind-phone-avatar-container {
   display: flex;
   justify-content: center;
 }
-.login-dialog {
+.bind-phone-dialog {
   padding-top: 20px;
   background-color: white;
   border-radius: 5px;
 }
-.login-btn {
+.bind-phone-btn {
   border-radius: 0;
 }
 .get-phone-btn button {

+ 8 - 9
wechat/pages/index/index.js

xqd xqd
@@ -34,6 +34,14 @@ Page({
       }
     })
     var pt_student = wx.getStorageSync('pt_student')
+    if (!pt_student) {
+      wx.redirectTo({
+        url: '/pages/login/index',
+      })
+    } else {
+      app.globalData.ptStudent = pt_student;
+    }
+
     wx.request({
       url: api.getShareInfoUrl,
       method: 'GET',
@@ -62,15 +70,6 @@ Page({
       }
     })
 
-    
-    
-    if (!pt_student) {
-      wx.redirectTo({
-        url: '/pages/login/index',
-      })
-    } else {
-      app.globalData.ptStudent = pt_student;
-    }
     wx.getLocation({
       success: (res) => {
         // let validLocation = this.validLocation(res.latitude, res.longitude)

+ 8 - 6
wechat/pages/login/index.js

xqd xqd xqd
@@ -22,9 +22,6 @@ Page({
       wx.showLoading({
         title: '登录中',
       })
-      console.log(wx.getStorageSync('we_chat_user_id'))
-      console.log(e.detail.iv)
-      console.log(e.detail.encryptedData)
       wx.request({
         url: api.updateUserInfoUrl,
         method: 'POST',
@@ -37,7 +34,7 @@ Page({
           if (info.data.status == 'success') {
             wx.setStorageSync('we_chat_user', info.data.data);
             wx.redirectTo({
-              url: 'pages/bind-phone/index',
+              url: '/pages/bind-phone/index',
             })
           }
         },
@@ -52,14 +49,19 @@ Page({
    * 生命周期函数--监听页面初次渲染完成
    */
   onReady: function () {
-  
+    var we_chat_user = wx.getStorageSync('we_chat_user')
+    if(we_chat_user) {
+      wx.redirectTo({
+        url: '/pages/bind-phone/index',
+      })
+    }
   },
 
   /**
    * 生命周期函数--监听页面显示
    */
   onShow: function () {
-  
+    
   },
 
   /**