"; $authorization=http_post_data($url,$data); $auth=json_decode($authorization,true); // print_r($authorization); $authapp=$auth['authorization_info']['authorizer_appid'];//拿到被授权公众号的APPid //获取公众号信息 $url1="https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_info?component_access_token=$token"; $data='{ "component_appid":"'.AppID.'" , "authorizer_appid": "'.$authapp.'" }'; // echo "
"; $authorizer_info=http_post_data($url1,$data); // print_r($authorizer_info); $info=json_decode($authorizer_info,true); $name=$info['authorizer_info']['nick_name'];//公众号名称 if(trim($name)==''){ print_r("超时,请返回重新授权."); exec("rm -f ".'jsonX/'.$AppID.'_token.json'); exit; } $head_img=$info['authorizer_info']['head_img'];//公众号图片 // echo ""; $user_name=$info['authorizer_info']['user_name'];//公众号图片 //MiniProgramInfo $mini=$info['authorizer_info']['MiniProgramInfo'];// $renzheng=trim($info['authorizer_info']['verify_type_info']); // print_r("qx:".json_encode($info['authorization_info']['func_info'][0])); $quanxian=trim($info['authorization_info']['func_info'][0]['funcscope_category']['id']); // echo '
权限:'.$quanxian; if (($quanxian==1) or ($quanxian==19)){ // echo "已经获得消息权限."; }else{ // echo "没获得消息权限."; } // echo "
认证状态:".$renzheng; if ($renzheng==0){ $rz='已认证,'; }else{ $rz='未认证,不支持接入'; } if(is_array($mini)){ $leixing= "小程序"; $huifu="进入小程序客服消息界面"; }else{ $leixing= "公众号"; $huifu="进入公众号界面,切换到发文字模式"; } // // print_r("
".$authorizer_info); if ($authapp<>''){ $res=file_put_contents("jsonX/auth_".$authapp.".json", $authorization); $res=file_put_contents("jsonX/info_".$user_name.".json", $authorizer_info); $zhuangtai= "授权成功"; }else{ $zhuangtai= "授权失败"; } $zhungtai= "您正在接入 $leixing : $name ".$zhuangtai.$rz; if (file_exists("jsonX/info_".$user_name.".json")){ $zhungtai.="对接生成!"; }else{ $zhungtai.="对接文件未生成,请重写对接!"; } //判断有没有 后台对接文件 if (file_exists("json/".$user_name.".json")){ // $ok=true; $zhungtai.="
您已经配置相关对接文件.如需重新配置,请联系本站管理员."; }else{ $ok=true; $zhungtai.="
现在开始设置管理员,请".$huifu.",发送openid 把收到的回复内容,填入下面的空格"; } ?> 智能客服-开通中

"; // echo $_GET['expires_in']; traceHttp(); function traceHttp() { logger("\n\nREMOTE_ADDR:".$_SERVER["REMOTE_ADDR"].(strstr($_SERVER["REMOTE_ADDR"],'101.226')? " FROM WeiXin": "Unknown IP")); logger("QUERY_STRING:".$_SERVER["QUERY_STRING"]); } function logger($log_content) { if(isset($_SERVER['HTTP_APPNAME'])){ //SAE sae_set_display_errors(false); sae_debug($log_content); sae_set_display_errors(true); }else{ //LOCAL $max_size = 500000; $log_filename = "log_wx.xml"; if(file_exists($log_filename) and (abs(filesize($log_filename)) > $max_size)){unlink($log_filename);} file_put_contents($log_filename, date('Y-m-d H:i:s').$log_content."\r\n", FILE_APPEND); } } function http_post_data($url, $data_string) { $ch = curl_init(); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json; charset=utf-8', 'Content-Length: ' . strlen($data_string)) ); ob_start(); curl_exec($ch); $return_content = ob_get_contents(); //echo $return_content."
"; ob_end_clean(); $return_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); // return array($return_code, $return_content); return $return_content; } function getToken($appid,$appsecret,$ComponentVerifyTicket,$jsonid){ $file = file_get_contents("jsonX/{$appid}_token.json",true); $result = json_decode($file,true); if (time() > $result['expires']){ $data = array(); $data['component_access_token'] = getNewToken($appid,$appsecret,$ComponentVerifyTicket); $data['expires']=time()+6200; $jsonStr = json_encode($data); $fp = fopen("jsonX/{$appid}_token.json", "w"); fwrite($fp, $jsonStr); fclose($fp); return $data['component_access_token']; }else{ return $result['component_access_token']; } } function getNewToken($appid,$appsecret,$ComponentVerifyTicket){ $data_string='{ "component_appid":"'.$appid.'" , "component_appsecret": "'.$appsecret.'", "component_verify_ticket": "'.$ComponentVerifyTicket.'" }'; $access_token_Arr =http_post_data("https://api.weixin.qq.com/cgi-bin/component/api_component_token", $data_string); //echo "
---"; $access_token_Arr=json_decode($access_token_Arr,true); return $access_token_Arr['component_access_token']; } ?>