如何编写公众号多客服功能开发代码?

作者:鱼爪创媒网 点击:9 发布时间:2021-11-08

  如何编写公众号多客服功能开发代码?随着微信公众号功能的不断的增加与开发,对于如何编写开发代码许多人都是不怎么清楚的,小编今天做了一番关于如何编写微信公号中多客服功能开发的代码的整理,来看看具体的编写流程。

  一、回复多客服消息

  开发模式接入客服系统。 接收到用户发送消息

  返回举例

  该消息的实现如下(以方倍工作室的微信公众平台PHP SDK为基础)

  //回复多客服消息

  EQYB  private function transmbcweuibhcuwbebc itService($object)

  {

  ERG $xmlTpl = "";

  ETWRUJ $result = sprintf($xmlTpl, $object->FromUserNbcwjuehcu ame, $object->ToUserName, time());

  AREWY return $result;

  }

  二、触发多客服会话

  触发关键词

  代码如下:

  //接收文本消息

  AERY private function receiveText($object)

  {

  AREHY $keyword = trim($object->Content);

  ARYB if (strstr($keyword, "投诉") || strstr($keyword, "你好") || strstr($keyword, "在吗")){

  Y HEY H$result = $this->trabhbdubc wekbjcbjsue cwnsmitService($object);

  }

  DHTBB return $result;

  }

  三、完整代码

  /*

  方倍工作室

  G CopyRight 2014 All Rights Reserved

  */

  TH define("TOKEN", "weixin");

  DYTJK $wechatObj = new wech YERUN  atCallbackapiTest();

  E5Y7NN if (!isset TRJHTY ($_GEcnwjohnqce T['echostr'])) {

  $wec  RTYatObj->responseMsg();

  }else{

  YRU6B$wechatObj->valid();

  }

  hkuy class wechatCal utkjlbackapiTest

  {

  //验证消息

  jhngviher public function valid()

  {

  frgfrt $echoStr = $_GET["echostr"];

  rtg4e if($this->checkSignature()){

  rtgge4 echo $echoStr;

  rgtrb exit;

  }

  }

  //检查签名

  rtgtr private function chetbbhtr ckSignature()

  {

  wegr $signature = $ rtg4r _GET["signature"];

  tdg 55hb $timestamp = $_GET["timestamp"];

  ergtrhb $nonce = $_GET["nonce"];

  kkaenrmbpigjr $token = TOKasrgrt EN;

  n vierhn $tmpArr = array($token, $timestamp, $nonce);

  ergvvy56 sort($tmpArr, SORT_STRING);

  ergvvy56$tmpStr = ergvvy56implode($tmpArr);

  ergvvy56 $tmpStr = ergvvy56 sha1($tmpStr);

  ergvvy56if($tmpStr == $sigergvvy56 nature){

  ergvvy56 returergvvy56 n true;

  }else{

  return false;

  }

  }

  //响应消息

  ergvvy56 public funcergvvy56 tion responseMsg()

  {

  ergvvy56 $postStr = $GLOergvvy56 BALS["HTTP_RAW_POST_DATA"];

  ergvvy56 if (!empty($postStr)){

  ergvvy56$this->logger("R "ergvvy56tring($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);

  ergvvy56 $RX_TYPE = trim($postObj->MsgType);

  ergvvy56 switcergvvy56 h ($RX_TYPE)

  {

  case "event":

  $ergvvy56 result = $this->receiveEvent($postObj);

  ergvvy56 break;

  case "text":

  ergvvy56 $result = $this->receiveText($postObj);

  break;

  }

  ergvvy56 $this->logger("T ".$result);

  echo $result;

  }else {

  echo "";

  exit;

  }

  }

  //接收事件消息

  private function receiveEvent($object)

  {

  switch ($object->Event)

  {

  case "subscribe":

  ergvvy56v$content[] = arergvvy56ray("Title" =>"欢迎关注方倍工作室", "Descripergvvy56tion" =>"使用方法: 1.发送快递单号,例如6367532560,可查询快递详情", "PicUrl" =>"http://www.3856.cc/weixin/weixin/logo.jpg", "Url" =>"");

  break;

  default:

  ergvvy56$content = "receergvvy56ive a new event: ".$object->Event;

  break;

  }

  if(is_array($content)){

  if (isset($content[0])){

  jsdvihneirs $result = $ergvvy56 this->transmitNews($object, $content);

  }else if (isset($content['MusicUrl'])){

  $result = $this->transmitMusic($object, $content);

  }

  }else{

  $result = $this->transmitText($object, $content);

  }

  return $result;

  }

  //接收文本消息

  private function receiveText($object)

  {

  $keyword = trim($object->Content);

  if($keyword == "时间" || $keyword == "测试"){

  $content = date("Y-m-d H:i:s",time());

  $result = $this->transmitText($object, $content);

  }

  //触发多客服模式

  else if (strstr($keyword, "您好") || strstr($keyword, "你好") || strstr($keyword, "在吗") || strstr($keyword, "有人吗")){

  $result = $this->transmitService($object);

  return $result;

  }

  return $result;

  }

  private function transmitText($object, $content)

  {

  $textTpl = "";

  $result = sprintf($textTpl, $object->FromUserName, $object->ToUserName, time(), $content);

  return $result;

  }

  private function transmitNews($object, $newsArray)

  {

  if(!is_array($newsArray)){

  return;

  }

  $itemTpl = "

  ";

  $item_str = "";

  jsvnnuiehsuo  foreach ($newsArray as $item){

  ddd $item_str .= sprintf($itemTpl, $item['Title'], $item['Description'], $item['PicUrl'], $item['Url']);

  }

  lwfjeivbje v $newsTpl = "";

  $result = sprintf($newsTpl, $object->FromUserName, $object->ToUserName, time(), count($newsArray));

  return $result;

  }

  private function transmitMusic($object, $musicArray)

  {

  $itemTpl = "

  ";

  $item_str = sprintf($itemTpl, $musicArray['Title'], $musicArray['Description'], $musicArray['MusicUrl'], $musicArray['HQMusicUrl']);

  $textTpl = "";

  $result = sprintf($textTpl, $object->FromUserName, $object->ToUserName, time());

  retuwv rn $result;

  }

  //回复多客服消息

  private function transmitService($object)

  {

  $xmlTpl = "";

  wvv$result = sprintf($xmlTpl, $object->Frwevcwerw omUserName, $object->ToUserName, time());

      3return $result;

  }

  wevc private function logger($log_content)

  {

  wevcfe if(isset($_SERVER['HTTP_APPNAME'])){ //SAE

  seff sae_set_display_errors(false);

  wef  swae_debug($log_content);

  wfew sae_set_display_errors(true);

  w23t }else if($_SERVER['REMOTE_ADDR'] != "127.0.0.1"){ //LOCAL

  ery $max_size = 10000;

  wVED $log_filename = "log.xml";

  ASREG ijwnbcfiewu    oh0  f(file_exists($log_filename) and (abs(filesize($log_filename)) > $max_size)){unlink($log_filename);}

  WEG4  finciwehfi   le_put_contents($log_filename, date('H:i:s')." ".$log_content." ", FILE_APPEND);

  }

  }

  }

  ?>

  如何编写公众号多客服功能开发代码?你会写代码了吗?其实小编很是佩服那些码农呢!微信公众号功能如此之多也多亏了他们!想要获取关于微信公众号素材内容,就请各位多多的关注鱼爪创媒吧。

  阅读推荐:

  微信公众号多客服功能的使用方法?

  微信公众号推广功能的使用方法?

  微信公众号一天发几篇文章好?

鱼爪创媒是一家专业提供公众号交易、公众号迁移、公众号增粉、公众号买卖交易的平台,如果您有这方面的需求,欢迎电话咨询:19180581726。有任何疑问,可以 【立即咨询】 我们平台的客服或者添加微信号 【19180581726】 。此文章来源于网络,如有侵权,请联系删除

标签:

资金保障

提供买卖双方资金担保交易
更放心

法律保障

交易签订具有法律效益合同
提供法律支持

急速退款

专属资金通道,快速拿到
钱款

全资公司

全资控股公司,大平台交易
有保障

服务优质

3500+专业团队,为您提供24
小时一对一贴心服务