1. 程式人生 > >公眾號開發之客服功能的群發消息功能

公眾號開發之客服功能的群發消息功能

eve end https code 程序 整理 customer status pty

本周我們做了一個有技術含量的一個新功能:客服功能的群發消息功能。此功能主要用於公眾號客服群發提醒,比如客戶的商家認證審核通過,用戶購買商品成功等功能提醒,可以有效減少網站項目開發所必要的資金節約。

  1. 接口代碼。

接口代碼如下:

public function reply_customer(){

$mtime=strtotime("-1 hour");

$where[‘add_time‘]=array("gt",$mtime);

$res=M("fa_need")->where($where)->order("id desc")->find();

$id=$res[‘id‘];

$new_time=time();

$go_time=$res[‘add_time‘]+$res[‘show_time‘]*60;

if($new_time<$go_time){

$credit_level=$res[‘credit_level‘];

$ya_money=$res[‘ya_money‘];

$wh[‘credit_level‘]=array("egt",$credit_level);

$wh[‘ya_money‘]=array("egt",$ya_money);

$wh[‘ya_money‘]=array("neq",$ya_money);

$wh[‘jie_status‘]=3;

$list=M("user")->where($wh)->limit(199)->select();

foreach ($list as $key => $value) {

$info[]=$value[‘openid‘];

}

$touser=I(‘touser‘);

$content="親,有新任務哦,可以點擊鏈接接單啦!";

//更換成自己的APPID和APPSECRET

$APPID="wx4ae938a141e9193a";

$APPSECRET="d0ef15664f42de92875f86b8f9f98edf";

$TOKEN_URL="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$APPID."&secret=".$APPSECRET;

$json=file_get_contents($TOKEN_URL);

$result=json_decode($json);

$ACC_TOKEN=$result->access_token;

foreach($info as $val){

$data = ‘{

"touser":"‘.$val.‘",

"msgtype":"text",

"text":

{

"content":"‘.$content.‘http://www.xxx.com/Task/task_details?id=‘.$id.‘"

}

}‘;

$url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=".$ACC_TOKEN;

$result = $this->https_post($url,$data);

$final = json_decode($result);

echo $final;

}

}

}

public function https_post($url,$data)

{

$curl = curl_init();

curl_setopt($curl, CURLOPT_URL, $url);

curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);

curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);

curl_setopt($curl, CURLOPT_POST, 1);

curl_setopt($curl, CURLOPT_POSTFIELDS, $data);

curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

$result = curl_exec($curl);

if (curl_errno($curl)) {

return ‘Errno‘.curl_error($curl);

}

curl_close($curl);

return $result;

}

  1. php調用接口代碼

Php代碼如下:

public function fa_need(){

vendor(‘Weixinup.jssdk‘);

$jssdk = new JSSDK("wx4ae938a141e9193a", "d0ef15664f42de92875f86b8f9f98edf");

$signPackage = $jssdk->GetSignPackage();

// var_dump($signPackage);die;

$this->assign(‘signPackage‘, $signPackage);

$uid=session(‘uid‘);

$model=M(‘user‘);

$list=$model->where("uid=$uid")->find();

$mod=M("school");

$school=$mod->select();

$this->reply_customer();

// if (I(‘id‘)!=""||!empty(I(‘id‘))) {

// $faid["id"] = I(‘id‘);

// $res = M("fa_need")->where($faid)->find();

// $this->assign("fa_needinfo",$res);

// }

$this->assign("school",$school);

$this->assign("list",$list);

$this->display();

}

  好了,到這裏大家應該清楚是如何實現的吧,那麽如果還是存在有不理解的地方,可以留言咨詢獲取幫助解答。

  本文由專業的鄭州小程序開發公司燚軒科技整理發布,原創不易,如需轉載請註明出處!

公眾號開發之客服功能的群發消息功能