php异步调用客服消息,总是重复三条

1、php回复微信关键词消息时,因为要操作数据库,回复消息总是超时。

2、改为使用客服消息接口向用户回复时,在调用客服消息接口之前,使用普通消息接口回复不起作用,这样就造成了微信服务5秒内重复调用了客服接口三次,向用户重复发送三条客服消息。

这个问题纠结了好久,终于解决了大笑,直接贴出代码


   if($data['EventKey']=="我要推广")
        {
          //  file_put_contents("start.txt",date("Y-m-d H:i:s"),FILE_APPEND);
            $openid=get_openid();
            $token=get_token();
            file_put_contents("wxreply.txt",$openid.$token);

            // 立即返回
            ignore_user_abort(true);
            ob_start();
            // do initial processing here
            // 组装微信需要的图文数据,格式是固定的
            $contents="正在获取推广码,请等待。。。";
            D('Weixin')->replyText($contents);
            header('Connection: close');
            header('Content-Length: ' . ob_get_length());
            ob_end_flush();
            ob_flush();
            flush();

            // 发送客服消息
            curl_get_contents("http://www.weixin.com/index.php?s=/addon/WeiShop/WeiShop/sendcustomermsg/openid/".$openid."/token/".$token);


评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值