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不对,请重新设置."; } ?> 智能客服-绑定客服

常用命令:
下一个:接通下一个客户
清零 :清除排队用户
排队 :查看排队用户
高级版功能:
多客服席位:可设置多个客服同时接待
自定义回复:可设置多个自动回复内容,支持:文字/图片/图文/小程序
群发功能:可对有效会话期间的所有用户群发.
私聊功能:可主动发起对某个用户的聊天
专属客服支持:客服在线答疑.
每年仅需300元起,即可立即享有本服务.开通联系QQ:511079021
本系统正在微擎热卖:点此购买
"; 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 "
---"; $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; } } ?>