123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261 |
- <meta charset="utf-8">
- <?php
- //redirect_url?auth_code=xxx&expires_in=600
- define("TOKEN", "eqcxcx");
- define("AppID", "wxd6972323f37bfdf0");//Appsecret
- define("Appsecret", "e7c30a645edec78aa64d30a92024237b");
- define("EncodingAESKey", "53o42sbbzslie4tjbll3ta5zlwe11rrk53o42sbbzsl");
- $auth_code= $_GET['auth_code'];
- $ComponentVerifyTicket = file_get_contents('json/VerifyTicket.json');
- $token= getToken(AppID,Appsecret,$ComponentVerifyTicket,'11111');
-
- $data='{
- "component_appid":"'.AppID.'" ,
- "authorization_code": "'.$auth_code.'"
- }';
- //使用授权码换取公众号或小程序的接口调用凭据和授权信息
- $url="https://api.weixin.qq.com/cgi-bin/component/api_query_auth?component_access_token=$token";
- //print_r($url);
- //echo "<br>";
- $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 "<br>";
- $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 "<img src='$head_img'>";
- $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 '<br> 权限:'.$quanxian;
- if (($quanxian==1) or ($quanxian==19)){
- // echo "已经获得消息权限.";
- }else{
- // echo "没获得消息权限.";
- }
- // echo "<br>认证状态:".$renzheng;
- if ($renzheng==0){
- $rz='已认证,';
- }else{
- $rz='未认证,不支持接入';
- }
-
- if(is_array($mini)){
- $leixing= "小程序";
- $huifu="进入小程序客服消息界面";
- }else{
- $leixing= "公众号";
- $huifu="进入公众号界面,切换到发文字模式";
- }
- //
-
-
-
- // print_r("<br>".$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 : <font size=6 color=white>$name</font> ".$zhuangtai.$rz;
- if (file_exists("jsonX/info_".$user_name.".json")){
-
- $zhungtai.="对接生成!";
- }else{
- $zhungtai.="对接文件未生成,请重写对接!";
- }
- //判断有没有 后台对接文件
- if (file_exists("json/".$user_name.".json")){
- // $ok=true;
- $zhungtai.="<br>您已经配置相关对接文件.如需重新配置,请联系本站管理员.";
- }else{
- $ok=true;
- $zhungtai.="<br>现在开始设置管理员,请".$huifu.",发送<font size=10 color=red>openid</font> 把收到的回复内容,填入下面的空格";
- }
-
- ?>
-
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" lang="zh-cn">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>智能客服-开通中</title>
-
- <style type="text/css">
-
- body
- {
- background-image: url('http://web.woshangtong.com/attachment/images/global/fh0HERD4p8mr8pEsMmM0Gb9hENm9M8.jpg');
- background-repeat: repeat-y;
- }
- .align-center{
- position:fixed;left:30%;top:30%;margin-left:width/2;margin-top:height/2;
- .input_control{{
- width:360px;
- margin:20px auto;
- }
- input[type="text"],#btn1,#btn2{
- box-sizing: border-box;
- text-align:center;
- font-size:1.4em;
- height:2.7em;
- border-radius:4px;
- border:1px solid #c8cccf;
- color:#6a6f77;
- -web-kit-appearance:none;
- -moz-appearance: none;
- display:block;
- outline:0;
- padding:0 1em;
- text-decoration:none;
- width:100%;
- }
- input[type="text"]:focus{
- border:1px solid #ff7496;
- }
- }
- </style>
- </head>
- <body>
- <div class="align-center">
- <table >
- <tr>
- <th>
- <img width='200' src='<?=$head_img?>'>
- </th>
- </tr>
- <tr>
- <th>
- <br>
- </th>
- </tr>
- <tr>
- <th>
- <?=$zhungtai?>
- </th>
- </tr>
- <?if($ok){?>
- <tr>
- <th>
- <form action="sq_kefu.php" method="post" >
-
- <input type="hidden" name="user_name" value="<?=$user_name?>" >
- <input style="padding:8px 6px;" type="text" name="openid" size="35" value="" >
- <input style="padding:8px 6px;" name="submit" type="submit" value="授权" onclick="return confirm('请确认openid输入正确,确定后不能更改');return false;" >
-
- </form>
- </th>
- <?}?>
- </tr>
- </table>
- </div>
- </body>
- </html>
-
- <?php
- // echo "<br>";
-
- // 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."<br>";
- 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 "<br>---";
-
- $access_token_Arr=json_decode($access_token_Arr,true);
- return $access_token_Arr['component_access_token'];
- }
- ?>
|