php 微信客服信息推送失败 微信重复推送客服消息 40001 45047
/***
* 微信客服发送信息
* 微信客服信息推送失败 微信重复推送客服消息 40001 45047
* 递归提交到微信 直到提交成功
* @param $openid
* @param int $is_repeat 是否递归
* @return bool
*/
function wx_kf_sendh($openid, $is_repeat = 0)
{
$result = M('Reply')->where("is_open=1")->order('listorder desc')->select(); if(!$is_repeat) {
$logarr = M('wx_kf_sendlog')->where("openid='".$openid."'")->order('createtime desc')->find();
if($logarr && $logarr['createtime'] > time()-10) {
return false;
}
$dddata['openid'] = $openid;
$dddata['createtime'] = time();
$dddata['text'] = 0; //1 发送成功 0失败
$dddata['image'] = 0; //1 发送成功 0失败
$dddata['diy'] = 0; //1 发送成功 0失败
$dddata['number'] = 0;
//$dddata['name'] = getVip($openid, 'nickname');
M('wx_kf_sendlog')->add($dddata);
} foreach ($result as $k => $v) { if (empty($v['type'])) {
continue;
} if ($v['type'] == 'text') {
$logarr = M('wx_kf_sendlog')->where("openid='".$openid."'")->order('createtime desc')->find();
if($logarr['text'] == '1') {
continue;
}
$str = str_replace("<br/>", '\n', $v['description']);
$str = str_replace(' ', '\r', $str);
$str = str_replace('href="', "href='", $str);
$str = str_replace('"', "'", $str);
$data = '{
"touser":"' . $openid . '",
"msgtype":"text",
"text":
{
"content":"' . $str . '"
}
}'; //发送信息
$appid = getids('config', 56, 'value');
$appsecret = getids('config', 57, 'value');
$accesstokenarr = getAccessToken($appid, $appsecret);
$access_token = $accesstokenarr['access_token'];
//通过基础消息接口发送的数据是XML格式的,但是调用客服接口发送的数据是json数据格式,更易传输。
$url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=" . $access_token; $rest = https_request($url, $data);
$jsonsarr = json_decode($rest, true);
if($jsonsarr['errcode'] != '0') { M('wx_kf_sendlog')->where("id=".$logarr['id'])->save(array('text'=>0, 'number'=>$logarr['number']+1,'logtime'=>$logarr['logtime'].'|text:'.date('Y-m-d H:i:s')));
wx_kf_send($openid,1);exit;
} else {
if($logarr['text'] == '0') {
M('wx_kf_sendlog')->where("id=".$logarr['id'])->save(array('text'=>1));
}
} } elseif ($v['type'] == 'image') { $logarr = M('wx_kf_sendlog')->where("openid='".$openid."'")->order('createtime desc')->find();
if($logarr['image'] == '1') {
continue;
} $data = '{
"touser":"' . $openid . '",
"msgtype":"image",
"image":
{
"media_id":"' . $v['media_id'] . '"
}
}'; //发送信息
$appid = getids('config', 56, 'value');
$appsecret = getids('config', 57, 'value');
$accesstokenarr = getAccessToken($appid, $appsecret);
$access_token = $accesstokenarr['access_token'];
//通过基础消息接口发送的数据是XML格式的,但是调用客服接口发送的数据是json数据格式,更易传输。
$url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=" . $access_token; $rest = https_request($url, $data);
$jsonsarr = json_decode($rest, true);
$logarr = M('wx_kf_sendlog')->where("openid='".$openid."'")->order('createtime desc')->find();
if($jsonsarr['errcode'] != '0') { M('wx_kf_sendlog')->where("id=".$logarr['id'])->save(array('image'=>0, 'number'=>$logarr['number']+1,'logtime'=>$logarr['logtime'].'|image:'.date('Y-m-d H:i:s')));
wx_kf_send($openid,1);exit;
} else {
if($logarr['text'] == '0') {
M('wx_kf_sendlog')->where("id=".$logarr['id'])->save(array('text'=>1));
}
} } elseif ($v['type'] == 'diy') {
$logarr = M('wx_kf_sendlog')->where("openid='".$openid."'")->order('createtime desc')->find();
if($logarr['diy'] == '1') {
continue;
}
$data = '{
"touser":"' . $openid . '",
"msgtype":"image",
"image":
{
"media_id":"' . down_share_img($openid) . '"
}
}'; //发送信息
$appid = getids('config', 56, 'value');
$appsecret = getids('config', 57, 'value');
$accesstokenarr = getAccessToken($appid, $appsecret);
$access_token = $accesstokenarr['access_token'];
//通过基础消息接口发送的数据是XML格式的,但是调用客服接口发送的数据是json数据格式,更易传输。
$url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=" . $access_token; $rest = https_request($url, $data);
$jsonsarr = json_decode($rest, true);
if($jsonsarr['errcode'] != '0') {
M('wx_kf_sendlog')->where("id=".$logarr['id'])->save(array('text'=>0, 'number'=>$logarr['number']+1,'logtime'=>$logarr['logtime'].'|diy:'.date('Y-m-d H:i:s')));
wx_kf_send($openid,1);exit;
} else {
if($logarr['diy'] == '0') {
M('wx_kf_sendlog')->where("id=".$logarr['id'])->save(array('diy'=>1));
}
} }
}
}
如果本文章已帮助到您!

php 微信客服信息推送失败 微信重复推送客服消息 40001 45047的更多相关文章
- 从苹果apns的feedback服务器获取推送失败的token
在开发自己的苹果推送服务时候,要合理的控制ios设备的Token,而这个Token是由苹果服务器Apns产生的,就是每次app问Apns要Token,由苹果服务器产生的Token会记录到Apns里面, ...
- 与众不同 windows phone (10) - Push Notification(推送通知)之推送 Tile 通知, 推送自定义信息
原文:与众不同 windows phone (10) - Push Notification(推送通知)之推送 Tile 通知, 推送自定义信息 [索引页][源码下载] 与众不同 windows ph ...
- 【Android应用开发】 推送原理解析 极光推送使用详解 (零基础精通推送)
作者 : octopus_truth 转载请注明出处 : http://blog.csdn.net/shulianghan/article/details/45046283 推送技术产生场景 : -- ...
- Android推送服务——百度云推送
一.推送服务简介 消息推送,顾名思义,是由一方主动发起,而另一方与发起方以某一种方式建立连接并接收消息.在Android开发中,这里的发起方我们把它叫做推送服务器(Push Server),接收方叫做 ...
- iOS8自定义推送显示按钮及推送优化
http://www.jianshu.com/p/803bfaae989e iOS8自定义推送显示按钮及推送优化 字数1435 阅读473 评论0 喜欢2 导语 在iOS8中,推送消息不再只是简单地点 ...
- Android高效率编码-第三方SDK详解系列(三)——JPush推送牵扯出来的江湖恩怨,XMPP实现推送,自定义客户端推送
Android高效率编码-第三方SDK详解系列(三)--JPush推送牵扯出来的江湖恩怨,XMPP实现推送,自定义客户端推送 很久没有更新第三方SDK这个系列了,所以更新一下这几天工作中使用到的推送, ...
- PhoneGap 的消息推送插件JPush极光推送
一. 什么是极光推送 极光推送,使得开发者可以即时地向其应用程序的用户推送通知或者消息,与用户保持互动, 从而有效地提高留存率,提升用户体验.平台提供整合了 Android 推送.iOS 推送的统一推 ...
- 百度收录检测并主动推送API(实时 mip推送通用)
简要描述: 百度收录检测并主动推送API(实时) 请求URL: api.bigjiji.com/baiduCheck_123456 调用方式: img标签 参数: 参数名 必选 类型 说明 site ...
- atitit.极光消息推送服务器端开发实现推送 jpush v3. 总结o7p
atitit.极光消息推送服务器端开发实现推送 jpush v3. 总结o7p 1. 推送所设计到底功能1 1.1. 内容压缩1 1.2. 多引擎1 2. reg ,设置appkey and pw ...
随机推荐
- Java设计模式—访问者模式
原文地址:http://www.cnblogs.com/java-my-life/archive/2012/06/14/2545381.html 总结的太棒啦,导致自己看了都不想总结了...... 在 ...
- 【MATLAB】R2017b两个镜像文件如何安装
1.采用DEAMON TOOLS加载镜像1. 2.当安装过程中弹出[请插入DVD2]时,在原来的盘符上面右键点击[装载],选择DVD2的镜像文件.在安装程序处选择[继续]即可正常安装.
- PHP腾讯与百度坐标转换
function coordinate_switch($a,$b){//百度转腾讯坐标转换 $a = Latitude , $b = Longitude $x = (double)$b - 0.006 ...
- 716. Max Stack (follow up questions for min stack)
Design a max stack that supports push, pop, top, peekMax and popMax. push(x) -- Push element x onto ...
- git报错error: src refspec refs/heads/master does not match any.
$ git pusherror: src refspec refs/heads/master does not match any.error: failed to push some refs 出错 ...
- Java中关于String的比较
关于String的各种==和equals,有的人搞不懂 简而言之 String s1 = "Hello" 声明的是一个常量,会在常量池里. ...
- AngularJS表格排序
<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...
- js关于密码框强弱度的提示
三种密码强度的正则表达式: 较弱:全是数字或全是字母 6-16个字符:/^[0-9]{6,16}$|^[a-zA-Z]{6,16}$/; 中级:数字.26个英文字母 6-16个字符: /^[A-Za- ...
- LeetCode13.罗马数字转整数 JavaScript
罗马数字包含以下七种字符: I, V, X, L,C,D 和 M. 字符 数值 I 1 V 5 X 10 L 50 C 100 D 500 M 1000 例如, 罗马数字 2 写做 II ,即为两个并 ...
- webpack4——打包html报错解决
①先引入html-webpack-plugin插件,然后在终端下载 npm install --save-dev html-webpack-plugin ②我的文件结构 ③修改webpack.dev. ...