Esempio n. 1
0
 private function onSubscribe($openid, $from)
 {
     $wxUserInfo = WxSDK::getUserInfo($openid, 'snsapi_base');
     if (empty($wxUserInfo)) {
         Log::warng('first get wxuinfo:' . $openid . ' userinfo fail from ' . $from);
         $wxUserInfo = WxSDK::getUserInfo($openid, 'snsapi_base');
         if (empty($wxUserInfo)) {
             Log::warng('second get wxuinfo:' . $openid . ' userinfo fail from ' . $from);
             return false;
         }
     }
     $userInfo = WxUserModel::findUserByOpenId($openid);
     if (empty($userInfo)) {
         WxUserModel::newOne($wxUserInfo, $from);
     } else {
         WxUserModel::updateWxUserInfo($userInfo, $wxUserInfo, $from);
     }
 }
Esempio n. 2
0
 private function toWxLogin()
 {
     $openInfo = WxSDK::getOpenInfo('snsapi_base', WX_APP_ID, WX_APP_SECRET);
     if (empty($openInfo['openid'])) {
         // TODO 这里要显示的告诉用户
         // header('Location: /TODO');
         // exit(0);
         return false;
     }
     $wxUserInfo = WxSDK::getUserInfo($openInfo['openid'], 'snsapi_base');
     if (empty($wxUserInfo)) {
         //
         Log::warng('first get wxuinfo:' . $openInfo['openid'] . ' fail when autologin');
         $wxUserInfo = WxSDK::getUserInfo($openInfo['openid'], 'snsapi_base');
         if (empty($wxUserInfo)) {
             //
             Log::warng('second get wxuinfo:' . $openInfo['openid'] . ' fail when autologin');
             // TODO 这里要显示的告诉用户
             // header('Location: /TODO');
             // exit(0);
             return false;
         }
     }
     $wxDBUserInfo = WxUserModel::findUserByOpenId($openInfo['openid']);
     if (empty($wxDBUserInfo)) {
         // new one
         $from = WxUserModel::SUBSCRIBE_FROM_ALREADY;
         if ((int) $wxUserInfo['subscribe'] == 0) {
             $from = WxUserModel::SUBSCRIBE_FROM_UNSUBSCRIBE;
         }
         $ret = WxUserModel::newOne($wxUserInfo, $from);
         if ($ret === false) {
             // TODO 这里要显示的告诉用户
             // header('Location: /TODO');
             // exit(0);
             return false;
         }
     }
     return $openInfo['openid'];
 }
Esempio n. 3
0
 private function toWxLogin()
 {
     $openInfo = WxSDK::getOpenInfo('snsapi_base', WX_APP_ID, WX_APP_SECRET);
     if (empty($openInfo['openid'])) {
         // TODO 这里要显示的告诉用户
         // header('Location: /TODO');
         // exit(0);
         return;
     }
     $wxUserInfo = WxSDK::getUserInfo($openInfo['openid'], 'snsapi_base');
     if (empty($wxUserInfo)) {
         //
         Log::warng('first get wxuinfo:' . $openInfo['openid'] . ' fail when autologin');
         $wxUserInfo = WxSDK::getUserInfo($openInfo['openid'], 'snsapi_base');
         if (empty($wxUserInfo)) {
             //
             Log::warng('second get wxuinfo:' . $openInfo['openid'] . ' fail when autologin');
             // TODO 这里要显示的告诉用户
             // header('Location: /TODO');
             // exit(0);
             return;
         }
     }
     $ret = WxUserModel::findUserByOpenId($openInfo['openid']);
     if (!empty($ret)) {
         $this->doLoginInWx($openInfo['openid']);
         return;
     } else {
         // create one
         $from = WxUserModel::SUBSCRIBE_FROM_ALREADY;
         if ((int) $wxUserInfo['subscribe'] == 0) {
             $from = WxUserModel::SUBSCRIBE_FROM_UNSUBSCRIBE;
         }
         $ret = WxUserModel::newOne($wxUserInfo, $from);
         if ($ret === false) {
             // TODO 这里要显示的告诉用户
             // header('Location: /TODO');
             // exit(0);
             return;
         }
         $ret = $this->doLoginInWx($openInfo['openid']);
         if ($ret === false) {
             Log::error("create wx user fail! " . json_encode($wxUserInfo, JSON_UNESCAPED_UNICODE));
             // TODO 这里要显示的告诉用户
             // header('Location: /TODO');
             // exit(0);
         }
     }
 }