$corpid], $insertData); } /** * 获取企业永久授权码 * */ public static function getPermanentCode($suiteId, $suiteTicket, $preAuthCode) { # 获取SuiteAccessToken // $suiteAccessToken = TokenService::getSuiteAccessToken($suiteId, $suiteTicket); $suiteAccessToken = TokenService::getAuthToken($suiteId, $suiteTicket); # 获取永久授权码链接 $permanentCodeUri = config('qyWechat.get_permanent_code'); $permanentCodeUri .= $suiteAccessToken; $postData = array('auth_code' => $preAuthCode); $response = HttpService::httpPost($permanentCodeUri, json_encode($postData)); $responseData = json_decode($response, true); return $responseData; } /** * corpid转换 * */ public static function getOpenCorpid($corpid, $suiteId, $suiteSecret) { # 获取SuiteAccessToken $suiteAccessToken = TokenService::getAuthToken($suiteId, $suiteSecret); // $suiteAccessToken = TokenService::getSuiteAccessToken($suiteId, $suiteSecret); $requestUri = config('qyWechat.get_open_corpid'); $requestUri .= $suiteAccessToken; $response = HttpService::httpPost($requestUri, json_encode(['corpid' => $corpid])); $responseData = json_decode($response, true); return $responseData; } /** * jsapi授权信息获取 * */ public static function getAuthData($corpid, $userId, $token, $timestamp, $url, &$errno) { # 验证合法性 $authToken = get_token($corpid, $userId, $timestamp); if($authToken != $token) { Log::logError('验签失败', [ 'corpid' => $corpid, 'user_id' => $userId, 'token' => $token, 'timestamp' => $timestamp, 'auth_token' => $authToken ], 'JsapiAuthData'); $errno = 1004; return []; } # 获取agentId $agentId = AuthorizeCorp::where('corpid', $corpid)->where('enable', 1)->value('agent_id'); if(empty($agentId)) { Log::logError('agentId获取失败', [ 'corpid' => $corpid, 'user_id' => $userId, 'token' => $token, 'timestamp' => $timestamp, 'auth_token' => $authToken ], 'JsapiAuthData'); $errno = 1004; return []; } # 获取企业jsapiTicket $jsapiTicket = AccessTokenService::getJsapiTicket($corpid); # 获取应用jsapiTicket $appJsapiTicket = AccessTokenService::getAppJsapiTicket($corpid); # 获取随机字符串和时间戳 $nonceStr = get_random_str(16); $timestamp = time(); $jsapiTicketStr = 'jsapi_ticket=' . $jsapiTicket . '&noncestr=' .$nonceStr. '×tamp='.$timestamp.'&url=' .$url; $appJsapiTicketStr = 'jsapi_ticket=' . $appJsapiTicket . '&noncestr=' .$nonceStr. '×tamp='.$timestamp.'&url=' .$url; $signature = sha1($jsapiTicketStr); $signatureApp = sha1($appJsapiTicketStr); return [ 'corpid' => $corpid, 'agent_id' => $agentId, 'timestamp' => $timestamp, 'nonce_str' => $nonceStr, 'signature' => $signature, 'app_signature' => $signatureApp ]; } /** * jsapi信息获取-公用 */ public static function getCommonAuthData($corpid, $url, &$errno) { # 获取agentId $agentId = AuthorizeCorp::where('corpid', $corpid)->where('enable', 1)->value('agent_id'); if(empty($agentId)) { Log::logError('agentId获取失败', [ 'corpid' => $corpid, 'url' => $url, ], 'getCommonAuthData'); $errno = 1004; return []; } # 获取企业jsapiTicket $jsapiTicket = AccessTokenService::getJsapiTicket($corpid); # 获取应用jsapiTicket $appJsapiTicket = AccessTokenService::getAppJsapiTicket($corpid); # 获取随机字符串和时间戳 $nonceStr = get_random_str(16); $timestamp = time(); $jsapiTicketStr = 'jsapi_ticket=' . $jsapiTicket . '&noncestr=' .$nonceStr. '×tamp='.$timestamp.'&url=' .$url; $appJsapiTicketStr = 'jsapi_ticket=' . $appJsapiTicket . '&noncestr=' .$nonceStr. '×tamp='.$timestamp.'&url=' .$url; $signature = sha1($jsapiTicketStr); $signatureApp = sha1($appJsapiTicketStr); return [ 'corpid' => $corpid, 'agent_id' => $agentId, 'timestamp' => $timestamp, 'nonce_str' => $nonceStr, 'signature' => $signature, 'app_signature' => $signatureApp ]; } }