fix: update AppID/AppSecret and fix wechatLogin undefined index errors
- Update AppID to wx2deff82b6c422615 - Update AppSecret for new AppID - Fix saveUseInfor: handle missing nickName/avatarUrl from getPhoneNumber - Fix wechatLogin: get openid from jscode2session response Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -15,8 +15,8 @@ class Cppwechat extends Base
|
|||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->Appid = 'wx0847525a15342a46';
|
$this->Appid = 'wx2deff82b6c422615';
|
||||||
$this->Appsecret = '71cf8c524580ba6b262e6dc52d44da4c';
|
$this->Appsecret = '447c3e46ce640ad772534c8f9161e1fd';
|
||||||
$this->TokenKey = 'ruilai340u20k4';
|
$this->TokenKey = 'ruilai340u20k4';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -281,9 +281,11 @@ class Cppwechat extends Base
|
|||||||
|
|
||||||
if (!isset($apiData['errcode'])) {
|
if (!isset($apiData['errcode'])) {
|
||||||
$sessionKey = $apiData['session_key'];
|
$sessionKey = $apiData['session_key'];
|
||||||
|
$openid = $apiData['openid'];
|
||||||
$errCode = $this->decryptData($sessionKey, $this->Appid, $encryptedData, $iv, $data);
|
$errCode = $this->decryptData($sessionKey, $this->Appid, $encryptedData, $iv, $data);
|
||||||
if ($errCode == 0) {
|
if ($errCode == 0) {
|
||||||
$record = json_decode($data, true);
|
$record = json_decode($data, true);
|
||||||
|
$record['openid'] = $openid;
|
||||||
$res = $this->saveUseInfor($record);
|
$res = $this->saveUseInfor($record);
|
||||||
return json_encode($res);
|
return json_encode($res);
|
||||||
} else {
|
} else {
|
||||||
@@ -301,13 +303,13 @@ class Cppwechat extends Base
|
|||||||
private function saveUseInfor($record)
|
private function saveUseInfor($record)
|
||||||
{
|
{
|
||||||
$data = array();
|
$data = array();
|
||||||
$data['nickname'] = $record['nickName'];
|
$data['nickname'] = isset($record['nickName']) ? $record['nickName'] : 'WeChat User';
|
||||||
$data['headimg'] = $record['avatarUrl'];
|
$data['headimg'] = isset($record['avatarUrl']) ? $record['avatarUrl'] : '';
|
||||||
|
|
||||||
$rec = Db::name('wechat_user')->field('uid')->where('openid', $record['openId'])->find();
|
$rec = Db::name('wechat_user')->field('uid')->where('openid', $record['openid'])->find();
|
||||||
|
|
||||||
if (empty($rec)) {
|
if (empty($rec)) {
|
||||||
$data['openid'] = $record['openId'];
|
$data['openid'] = $record['openid'];
|
||||||
$data['create_time'] = date('Y-m-d H:i:s');
|
$data['create_time'] = date('Y-m-d H:i:s');
|
||||||
$res = Db::name('wechat_user')->insertGetId($data);
|
$res = Db::name('wechat_user')->insertGetId($data);
|
||||||
$uid = $res;
|
$uid = $res;
|
||||||
|
|||||||
Reference in New Issue
Block a user