/***
* 微信客服发送信息
* 微信客服信息推送失败 微信重复推送客服消息 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('&nbsp;', '\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的更多相关文章

  1. 从苹果apns的feedback服务器获取推送失败的token

    在开发自己的苹果推送服务时候,要合理的控制ios设备的Token,而这个Token是由苹果服务器Apns产生的,就是每次app问Apns要Token,由苹果服务器产生的Token会记录到Apns里面, ...

  2. 与众不同 windows phone (10) - Push Notification(推送通知)之推送 Tile 通知, 推送自定义信息

    原文:与众不同 windows phone (10) - Push Notification(推送通知)之推送 Tile 通知, 推送自定义信息 [索引页][源码下载] 与众不同 windows ph ...

  3. 【Android应用开发】 推送原理解析 极光推送使用详解 (零基础精通推送)

    作者 : octopus_truth 转载请注明出处 : http://blog.csdn.net/shulianghan/article/details/45046283 推送技术产生场景 : -- ...

  4. Android推送服务——百度云推送

    一.推送服务简介 消息推送,顾名思义,是由一方主动发起,而另一方与发起方以某一种方式建立连接并接收消息.在Android开发中,这里的发起方我们把它叫做推送服务器(Push Server),接收方叫做 ...

  5. iOS8自定义推送显示按钮及推送优化

    http://www.jianshu.com/p/803bfaae989e iOS8自定义推送显示按钮及推送优化 字数1435 阅读473 评论0 喜欢2 导语 在iOS8中,推送消息不再只是简单地点 ...

  6. Android高效率编码-第三方SDK详解系列(三)——JPush推送牵扯出来的江湖恩怨,XMPP实现推送,自定义客户端推送

    Android高效率编码-第三方SDK详解系列(三)--JPush推送牵扯出来的江湖恩怨,XMPP实现推送,自定义客户端推送 很久没有更新第三方SDK这个系列了,所以更新一下这几天工作中使用到的推送, ...

  7. PhoneGap 的消息推送插件JPush极光推送

    一. 什么是极光推送 极光推送,使得开发者可以即时地向其应用程序的用户推送通知或者消息,与用户保持互动, 从而有效地提高留存率,提升用户体验.平台提供整合了 Android 推送.iOS 推送的统一推 ...

  8. 百度收录检测并主动推送API(实时 mip推送通用)

    简要描述: 百度收录检测并主动推送API(实时) 请求URL: api.bigjiji.com/baiduCheck_123456 调用方式: img标签 参数: 参数名 必选 类型 说明 site ...

  9. atitit.极光消息推送服务器端开发实现推送  jpush v3. 总结o7p

    atitit.极光消息推送服务器端开发实现推送  jpush v3. 总结o7p 1. 推送所设计到底功能1 1.1. 内容压缩1 1.2. 多引擎1 2. reg  ,设置appkey and pw ...

随机推荐

  1. 【Linux】 静态函数库设计

    一.外部函数来源-- 函数库&系统调用 二.函数库分类 静态函数库 --多份拷贝 动态函数库 --单份拷贝 区别 链接方式区别 三.函数库存放位置 Linux应用程序使用的主要函数库均存放于/ ...

  2. Jmeter性能测试 入门--转载

    转载: Jmeter性能测试 入门 Jmeter是一款优秀的开源测试工具, 是每个资深测试工程师,必须掌握的测试工具,熟练使用Jmeter能大大提高工作效率. 熟练使用Jmeter后, 能用Jmete ...

  3. linux c 遍历目录及文件

    #include <dirent.h>void recovery_backend() { DIR * pdir ; struct dirent * pdirent; struct stat ...

  4. Siebel 集成中的“发布-订阅”与“阅读”

    将 Siebel 应用程序中存储的数据提供给企业中的其他应用程序时,通常需要遵循以下两种基本模式之一: 发布-订阅 阅读 “发布-订阅”是一种机制,根据该机制,一个系统(发布者)将更改或更新的数据提供 ...

  5. Sql根据经纬度算出距离

    SELECT  ISNULL((2 * 6378.137 * ASIN(SQRT(POWER(SIN((117.223372- ISNULL(Latitude,0) )*PI()/360),2)+CO ...

  6. SpringMVC方法接收参数可以为空、默认值设置

  7. Linux 网卡的解决方法

    1. 编辑70-persistent-net配置文件: # vi /etc/udev/rules.d/70-persistent-net.rules 如果没有就新建一个,添加如下内容: # PCI d ...

  8. IOS Core Motion、UIAccelerometer(加速计使用)

    加速计 ● 加速计的作用 ● 用于检测设备的运动(比如摇晃) ● 加速计的经典应用场景 ● 摇一摇 ● 计步器 ● 加速计程序的开发 ● 在iOS4以前:使用UIAccelerometer,用法非常简 ...

  9. IOS 即时通讯的框架 配置环境

    一.了解XMPP 协议(标准)XMPP 即时通讯协议SGIP 短信网关协议 这手机发短信 移动支付和网页支付 0x23232[0,1] 0x23232 0x23232 0x23232 只有协议,必须会 ...

  10. POJ-2886 Who Gets the Most Candies?---线段树+约瑟夫环

    题目链接: https://cn.vjudge.net/problem/POJ-2886 题目大意: N个人围成一圈第一个人跳出圈后会告诉你下一个谁跳出来跳出来的人(如果他手上拿的数为正数,从他左边数 ...