Jelajahi Sumber

完善小程序相关的接口及上传图片摆正

齐博 6 tahun lalu
induk
melakukan
acaf9924ae

+ 1 - 1
application/common/model/Reply.php

@@ -121,7 +121,7 @@ abstract class Reply extends Model
                 empty($pages[1])?[]:$pages[1]
                 );
         
-        $data_list->each(function($rs,$key){
+        $data_list->each(function(&$rs,$key){
             $rs['username'] = get_user_name($rs['uid']);
             $rs['user_icon'] = get_user_icon($rs['uid']);
             if($rs['mvurl']){

+ 1 - 0
application/common/upgrade/13.sql

@@ -0,0 +1 @@
+ALTER TABLE  `qb_bbs_reply` ADD  `mvurl` VARCHAR( 255 ) NOT NULL AFTER  `picurl`;

+ 13 - 42
application/index/controller/wxapp/Login.php

@@ -30,67 +30,38 @@ class Login extends IndexBase
      */
     public function index($code='',$encryptedData='',$iv=''){
         if($code=='the code is a mock one'||empty($code)){
-            $data = [
-                    'meta'=>[
-                            'code'=>1,
-                            'message'=>'无法登录,code 获取失败',
-                    ],
-                    'data'=>[
-                            'code'=>$code,
-                            'token'=>'',                            
-                    ],
-            ];
-            return json($data);
+            return $this->err_js('无法登录,code 获取失败');
         }
         $array = AuthAPI::login($code, $encryptedData, $iv);
+        if(!is_array($array)){
+            return $this->err_js($array);
+        }
         $skey = $array['skey'];
         $sessionKey = $array['sessionKey'];
         $info = $array['userinfo'];
         $openid = $info['openId'];
         
         if (empty($openid)) {
-            $data = [
-                    'meta'=>[
-                            'code'=>1,
-                            'message'=>'登录失败,openid获取不到',
-                    ],
-                    'data'=>[
-                            'token'=>''
-                    ],
-            ];
-            return json($data);
+            return $this->err_js('登录失败,openid获取不到');
         }
+        
         $user = UserModel::check_wxappIdExists($openid);
         if(empty($user)){
             $user = UserModel::api_reg($openid,$info);
             if(empty($user['uid'])){
-                $data = [
-                        'meta'=>[
-                                'code'=>1,
-                                'message'=>'注册失败',
-                        ],
-                        'data'=>[
-                                'msg'=>$user
-                        ],
-                ];
-                return json($data);
+                return $this->err_js('注册失败');
             }
-        }        
+        }
+        
         UserModel::login($user['username'], '', '',true);   //这个并不能真正的登录.只是做一些登录的操作日志及其它接口处理
         
         $user = UserModel::get_info($user['uid']);
         cache($skey,"{$user['uid']}\t{$user['username']}\t".mymd5($user['password'],'EN')."\t$sessionKey",3600*72);
-        $data = [
-                'meta'=>[
-                        'code'=>0,
-                        'message'=>'登录成功',
-                ],
-                'data'=>[
-                        'token'=>$skey,
-                        'userInfo'=>UserModel::get_info($user['uid']),
-                ],
+        $array = [
+                'token'=>$skey,
+                'userInfo'=>UserModel::get_info($user['uid']),
         ];
-        return json($data);
+        return $this->ok_js($array);
     }
     
     /**

+ 7 - 11
application/shop/index/wxapp/Index.php

@@ -32,19 +32,15 @@ class Index extends _Index
      * @return \think\response\Json
      */
     public function banner(){
-        $map = ['status'=>2];
+        $map = [];
         $map['ispic'] = 1;
         $rows = 4;
-        $array = getArray( $this->model->getListByMid(1,$map,'id desc',$rows) );
-        $items = [];        
-        foreach($array['data'] AS $rs){
-            $items[] = [
-                    'id' => $rs['id'],
-                    'name' => $rs['title'],
-                    'picurl' => $rs['picurl'],
-            ];
-        }
-        return $this->ok_js($items);
+        $array = $this->model->getListByMid(1,$map,'id desc',$rows);
+        $array->each(function(&$rs){
+            unset($rs['content'],$rs['full_content']);
+            return $rs;
+        });
+        return $this->ok_js($array);
     }
 }
 

File diff ditekan karena terlalu besar
+ 2 - 0
public/static/js/exif.js


+ 15 - 6
vendor/weapp-sdk/lib/Auth/AuthAPI.php

@@ -11,7 +11,7 @@ use \QCloud_WeApp_SDK\Helper\Request as Request;
 
 class AuthAPI {
     /**
-     * 用户登录接口
+     * 用户登录接口,验证失败时,返回错误代码字符串
      * @param {string} $code        wx.login 颁发的 code
      * @param {string} $encryptData 加密过的用户信息
      * @param {string} $iv          解密用户信息的向量
@@ -20,6 +20,10 @@ class AuthAPI {
     public static function login($code, $encryptData, $iv) {
         // 1. 获取 session key
         $sessionKey = self::getSessionKey($code);
+        
+        if(is_array($sessionKey)){  //session key获取不到
+            return $sessionKey['errmsg'];
+        }
 
         // 2. 生成 3rd key (skey)
         $skey = sha1($sessionKey . mt_rand());
@@ -75,7 +79,7 @@ class AuthAPI {
      * 通过 code 换取 session key
      * @param {string} $code
      */
-    public static function getSessionKey ($code) {
+    public static function getSessionKey($code) {
         $useQcProxy = Conf::getUseQcloudLogin();
 
         /**
@@ -89,9 +93,13 @@ class AuthAPI {
             list($session_key, $openid) = array_values(self::useQcloudProxyGetSessionKey($secretId, $secretKey, $code));
             return $session_key;
         } else {
-            $appId = Conf::getAppId();
-            $appSecret = Conf::getAppSecret();
-            list($session_key, $openid) = array_values(self::getSessionKeyDirectly($appId, $appSecret, $code));
+            $appId = config('webdb.wxapp_appid');//Conf::getAppId();
+            $appSecret = config('webdb.wxapp_appsecret');//Conf::getAppSecret();
+            $array = self::getSessionKeyDirectly($appId, $appSecret, $code);
+            if(!is_array($array)){      //验证失败,返回的字符串
+                return ['errmsg'=>$array];
+            }
+            list($session_key, $openid) = array_values($array);
             return $session_key;
         }
     }
@@ -117,7 +125,8 @@ class AuthAPI {
         ]));
 
         if ($status !== 200 || !$body || isset($body['errcode'])) {
-            throw new Exception(Constants::E_PROXY_LOGIN_FAILED . ': ' . json_encode($body));
+            return $status !== 200 ? '无法打开微信服务器' : $appId.'验证失败,错误代码是: ' . $body['errcode'] . ' 详情:' . $body['errmsg'];
+            //throw new Exception(Constants::E_PROXY_LOGIN_FAILED . ': ' . json_encode($body));
         }
 
         return $body;

Beberapa file tidak ditampilkan karena terlalu banyak file yang berubah dalam diff ini