123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285 |
- <?php
- /*
- 易企程客服平台
- CopyRight 2018 All Rights Reserved
- */
- define("TOKEN", "eqcxcx");
- define("AppID", "wxd6972323f37bfdf0");//Appsecret
- define("Appsecret", "e7c30a645edec78aa64d30a92024237b");
- define("EncodingAESKey", "53o42sbbzslie4tjbll3ta5zlwe11rrk53o42sbbzsl");
- $user_name = trim($_POST['user_name']);
- $openid = trim($_POST['openid']);
- //下发一条确认消息 .
- $ComponentVerifyTicket = file_get_contents('json/VerifyTicket.json');//yaoshi
- $Mtoken= getMToken(AppID,Appsecret,$ComponentVerifyTicket,'11111');//拿到自己的密钥
- //$this->logger(" M \r\n".$ComponentVerifyTicket);
- //$this->logger(" M \r\n".$Mtoken);
- $ToUserName=$user_name; // 获取当前公众号的name
-
- $info = json_decode(file_get_contents("jsonX/info_".$ToUserName.".json"),true);//读取设置文件.
- $mini=$info['authorizer_info']['MiniProgramInfo'];
- if (is_array($mini)) { $xcx= true; }else{ $xcx= false; }
- $name=$info['authorizer_info']['nick_name'];//公众号名称
- $signature=$info['authorizer_info']['signature'];//公众号名称 signature
- $head_img=$info['authorizer_info']['head_img'];//公众号图片
- $Cappid=$info['authorization_info']['authorizer_appid'];
- $refresh_token=$info['authorization_info']['authorizer_refresh_token'];
-
- $Atoken= getCToken(AppID,$Cappid,$refresh_token,$Mtoken);
- $url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=".$Atoken;
- $aaa=sendmsg($openid,'text','收到本信息,表明您的设置已经成功!可以使用啦','',$url);//给用户发消息.
- if (json_decode($aaa, true)['errcode']==0){
- //发送成功!设置路径
-
- //
- $arr=array(
- 'uniacid' => $ToUserName,
- 'bakuniacid' => 149,
- 'website' => 'http://'.$_SERVER['HTTP_HOST'],
- 'openids' => $openid,
- '结束语' => '感谢您访问'.$name
- );
- $res=file_put_contents("json/".$ToUserName.".json", json_encode($arr));
- $kefuarr=array($openid=>"");
- $kefulistarr=array($openid=>"客服");
- $res=file_put_contents("json/".$ToUserName."_kefu.json", json_encode($kefuarr));
- $res=file_put_contents("json/".$ToUserName."_kefulist.json", json_encode($kefulistarr));
- if(file_exists("json/".$ToUserName."_kefulist.json")){
- $bakmsg="设置成功!";
- $path="jsonX/zhucelist.json";
- $data=array('ToUserName'=>$ToUserName,'name'=>$name,'head_img'=>$head_img);
- savejson($path,json_encode($data));
- }
- else{$bakmsg="文件创建失败,请检查权限!";}
-
- }else{
- //openid不对 .提示重新发送.
- $bakmsg= "openid不对,请重新设置.";
-
- }
-
- ?>
- <!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">
- .center
- {
- margin-left:auto;
- opacity:0.5;
- width:70%;
- background-color:#b0e0e6;
- }
- body
- {
- background-image: url('http://web.woshangtong.com/attachment/images/global/fh0HERD4p8mr8pEsMmM0Gb9hENm9M8.jpg');
- background-repeat: repeat-y;
- }
- .align-center{
- position:fixed;left:10%;top:30%;margin-left:width/2;margin-top:height/2;
- }
- </style>
- </head>
- <body>
- <div class="align-center">
- <table >
- <tr>
- <th>
- <img width='200' src='logo.png'>
- </th>
-
- <th width=400 >
- <div class="center">
- <br><?if($bakmsg=="设置成功!"){?>
- 常用命令:<br>
- 下一个:接通下一个客户<br>
- 清零 :清除排队用户<br>
- 排队 :查看排队用户<br>
- </div>
- </th>
-
- <th>
- <div class="center">
- 高级版功能:<br>
- 多客服席位:可设置多个客服同时接待<br>
- 自定义回复:可设置多个自动回复内容,支持:文字/图片/图文/小程序<br>
- 群发功能:可对有效会话期间的所有用户群发.<br>
- 私聊功能:可主动发起对某个用户的聊天<br>
- 专属客服支持:客服在线答疑.<br>
-
- 每年仅需300元起,即可立即享有本服务.开通联系QQ:511079021<br>
-
- 本系统正在微擎热卖:<a href='https://s.we7.cc/module-9528.html'>点此购买</a>
- </div>
- <?}?>
- </th>
-
- <th>
- <font size=20 color=red><?=$bakmsg?></font>
- </th>
- </tr>
- </table>
- </div>
- </body>
- </html>
-
- <?php
- 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 getMToken($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()+7200;
- $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'];
- }
- function getNewCToken($Mappid,$Cappid,$refresh_token,$Mtoken){
- $data_string='{
- "component_appid":"'.$Mappid.'",
- "authorizer_appid":"'.$Cappid.'",
- "authorizer_refresh_token":"'.$refresh_token.'",
- }';
- $access_token_Arr = http_post_data("https://api.weixin.qq.com/cgi-bin/component/api_authorizer_token?component_access_token=$Mtoken", $data_string);
-
-
- //$access_token_Arr=json_decode($access_token_Arr,true);
- return $access_token_Arr;
- }
- function getCToken($Mappid,$Cappid,$refresh_token,$Mtoken){
-
- $file = file_get_contents("jsonX/{$Cappid}_token.json",true);
- $result = json_decode($file,true);
- if (time() > $result['expires']){
- // $data = array();
- $jsonStr = getNewCToken($Mappid,$Cappid,$refresh_token,$Mtoken);
-
- // $jsonStr = json_encode($data);
- $fp = fopen("jsonX/{$Cappid}_token.json", "w");
- fwrite($fp, $jsonStr);
- fclose($fp);
- $data=json_decode($jsonStr,true);
- return $data['authorizer_access_token'];
- }else{
- return $result['authorizer_access_token'];
- }
- }
-
- function sendmsg($openid,$msgtype,$keyword,$postObj,$url){
- //消息处理模块.
- switch ($msgtype)
- {
- case 'text':
- $data1='{ "touser":"'.$openid.'", "msgtype":"text",
- "text": { "content":" '.$keyword.' " } }';
- break;
- case 'image':
-
- $MediaId = $postObj->MediaId;
-
- $data1=' { "touser":"'.$openid.'", "msgtype":"image",
- "image": { "media_id":"'.$MediaId.'" }}';
- break;
- case 'voice':
-
- $MediaId = $postObj->MediaId;
-
- $Recognition = $postObj->Recognition;
- $data1=' { "touser":"'.$openid.'", "msgtype":"voice",
- "voice": { "media_id":"'.$MediaId.'" }}';
- break;
- case 'miniprogrampage':
- $data1='';
- break;
- default:
- $data1='';
- }
-
- $aaa = http_post_data($url, $data1);
-
- // echo '发送消息:'.$data1.$aaa;
- // logger('@@@@@@@@'.$data1.$aaa);
-
- return $aaa;
- }
- function savejson($path,$data){ //保存1行
-
- //去除重复
- $lines = file($path);
- $i=0;
- $cf=0;
- foreach ($lines as $line) {
- $line = rtrim($line);
- $i++;
- // print("$line\n");
- if ($data==$line){
- $cf=$i;
- break;
- }
- // more statements...
- }
- if ($cf==0) {
- // echo "newone:\n";
- file_put_contents($path, $data.PHP_EOL, FILE_APPEND);
- return $cf;
- }
- else{
- return $cf;
- }
-
- }
-
- ?>
|