menuFrame = 'wxapp'; $this->type = ACCOUNT_TYPE_APP_AUTH; $this->typeName = '小程序'; $this->typeSign = WEBAPP_TYPE_SIGN; } function fetchAccountInfo() { if ($this->uniaccount['key'] == 'wx570bc396a51b8ff8') { $this->uniaccount['key'] = $this->appid; $this->account = $this->uniaccount; $this->openPlatformTestCase(); } $account_table = table('account'); $account = $account_table->getWxappAccount($this->uniaccount['acid']); $account['encrypt_key'] = $this->appid; return $account; } function accountDisplayUrl() { return url('account/display', array('type' => WXAPP_TYPE_SIGN)); } public function getAuthLoginUrl() { $preauthcode = $this->getPreauthCode(); if (is_error($preauthcode)) { $authurl = "javascript:alert('{$preauthcode['message']}');"; } else { $authurl = sprintf(ACCOUNT_PLATFORM_API_LOGIN, $this->appid, $preauthcode, urlencode($GLOBALS['_W']['siteroot'] . 'index.php?c=wxapp&a=auth&do=forward'), ACCOUNT_PLATFORM_API_LOGIN_WXAPP); } return $authurl; } public function getOauthInfo($code = '') { $component_accesstoken = $this->getComponentAccesstoken(); if (is_error($component_accesstoken)) { return $component_accesstoken; } $apiurl = sprintf(self::JSCODEURL, $this->account['key'], $code, $this->appid, $component_accesstoken); $response = $this->request($apiurl); if (is_error($response)) { return $response; } cache_write(cache_system_key('account_auth_accesstoken', array('key' => $this->account['key'])), $response['refresh_token']); return $response; } protected function setAuthRefreshToken($token) { $tablename = 'account_wxapp'; pdo_update($tablename, array('auth_refresh_token' => $token), array('acid' => $this->account['acid'])); cache_write(cache_system_key('account_auth_accesstoken', array('key' => $this->account['key'])), $token); } public function pkcs7Encode($encrypt_data, $iv) { $key = base64_decode($_SESSION['session_key']); $result = aes_pkcs7_decode($encrypt_data, $key, $iv); if (is_error($result)) { return error(1, '解密失败'); } $result = json_decode($result, true); if (empty($result)) { return error(1, '解密失败'); } if ($result['watermark']['appid'] != $this->account['key']) { return error(1, '解密失败'); } unset($result['watermark']); return $result; } public function result($errno, $message = '', $data = '') { exit(json_encode(array( 'errno' => $errno, 'message' => $message, 'data' => $data, ))); } }