|
|
|
@ -71,6 +71,17 @@ class OpenPlatform extends BaseServices { |
|
|
|
|
if (isset($message['InfoType'])) { |
|
|
|
|
// 授权事件 日志记录 |
|
|
|
|
$this->addComponentCallBackRecord($message); |
|
|
|
|
switch ($message['InfoType']) { |
|
|
|
|
case 'authorized': |
|
|
|
|
case 'updateauthorized': |
|
|
|
|
$this->addAuthorizerInfo($message); |
|
|
|
|
break; |
|
|
|
|
case 'unauthorized': |
|
|
|
|
$this->delAuthorizerInfo($message); |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} else if (isset($message['MsgType'])) { |
|
|
|
|
// 消息与事件通知 日志记录 |
|
|
|
|
$this->addWxcallbackBizRecord($message, $appid); |
|
|
|
@ -131,6 +142,57 @@ class OpenPlatform extends BaseServices { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 保存小程序信息 |
|
|
|
|
* */ |
|
|
|
|
public function addAuthorizerInfo($data) |
|
|
|
|
{ |
|
|
|
|
$program = $this->app->getAuthorizer($data['AuthorizerAppid']); |
|
|
|
|
$program_authorizer_info = $program['authorizer_info']; |
|
|
|
|
$program_authorization_info = $program['authorization_info']; |
|
|
|
|
// 有时候平台不返回refresh_token,需要根据code手动去获取refresh_token |
|
|
|
|
// 刷新令牌authorizer_refresh_token是需要一直保存的?有有效期这个说法吗? |
|
|
|
|
// https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/troubleshooting/TroubleShooting.html |
|
|
|
|
if (!$program_authorization_info['authorizer_refresh_token']){ |
|
|
|
|
$program_authorization_info = $this->app->handleAuthorize($data['AuthorizationCode']); |
|
|
|
|
$program_authorization_info = $program_authorization_info['authorization_info']; |
|
|
|
|
} |
|
|
|
|
$insert_data = [ |
|
|
|
|
'platform_id' => 5, |
|
|
|
|
'appid' => $program_authorization_info['authorizer_appid'] ?? '', |
|
|
|
|
'refreshtoken' => $program_authorization_info['authorizer_refresh_token'] ?? '', |
|
|
|
|
'auth_time' => time(), |
|
|
|
|
'app_type' => isset($program_authorizer_info['MiniProgramInfo']), |
|
|
|
|
'nick_name' => $program_authorizer_info['nick_name'] ?? '', |
|
|
|
|
'user_name' => $program_authorizer_info['user_name'] ?? '', |
|
|
|
|
'head_img' => $program_authorizer_info['head_img'] ?? '', |
|
|
|
|
'qrcode_url' => $program_authorizer_info['qrcode_url'] ?? '', |
|
|
|
|
'principal_name' => $program_authorizer_info['principal_name'] ?? '', |
|
|
|
|
'register_type' => $program_authorizer_info['register_type'] ?? '', |
|
|
|
|
'verify_info' => $program_authorizer_info['verify_type_info']['id'] ?? '', |
|
|
|
|
'service_type' => $program_authorizer_info['service_type_info']['id'] ?? '', |
|
|
|
|
'account_status' => $program_authorizer_info['account_status'] ?? '', |
|
|
|
|
'is_phone' => $program_authorizer_info['basic_config']['is_phone_configured'] ?? '', |
|
|
|
|
'is_email' => $program_authorizer_info['basic_config']['is_email_configured'] ?? '', |
|
|
|
|
'func_info' => $program_authorization_info['func_info'] ? json_encode($program_authorization_info['func_info'], JSON_UNESCAPED_UNICODE) : '', |
|
|
|
|
'json_data' => json_encode($program, true), |
|
|
|
|
]; |
|
|
|
|
$row = Authorizers::find(['appid' => $insert_data['appid']]); |
|
|
|
|
if ($row){ |
|
|
|
|
Authorizers::update($insert_data, ['appid' => $insert_data['appid']]); |
|
|
|
|
}else{ |
|
|
|
|
Authorizers::create($insert_data); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 删除小程序授权信息 |
|
|
|
|
* @return void |
|
|
|
|
*/ |
|
|
|
|
public function delAuthorizerInfo($data){ |
|
|
|
|
Authorizers::destroy(['appid' => $data['appid']]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function getTemplate() |
|
|
|
|
{ |
|
|
|
|
return $this->app->code_template->list(); |
|
|
|
@ -164,7 +226,7 @@ class OpenPlatform extends BaseServices { |
|
|
|
|
public function getPcAuthorizerUrl() |
|
|
|
|
{ |
|
|
|
|
$pre_code = $this->app->createPreAuthorizationCode(); |
|
|
|
|
$callback = env('SITE_URL') . '/wechat/callback'; |
|
|
|
|
$callback = env('SITE_URL') . '/auth/callback'; |
|
|
|
|
$pc_url = $this->app->getPreAuthorizationUrl($callback, $pre_code); |
|
|
|
|
$mobile_url = $this->app->getMobilePreAuthorizationUrl($callback, $pre_code); |
|
|
|
|
return [ |
|
|
|
|