function send() { $uid = $this->_post('uid'); $content = parent::_postContent('content'); if (!$uid) { $this->JsonReturn('参数丢失', array('code' => '', 'msg' => ''), 0); } if (!$content) { $this->JsonReturn('回复内容不能为空', array('code' => '', 'msg' => ''), 0); } $touser = D('member')->getOpenidByUids($uid); if (!$touser) { $this->JsonReturn('用户不存在', array('code' => '', 'msg' => ''), 0); } $sendInfo = array('touser' => $touser, 'msgtype' => 'text', 'text' => array('content' => $content)); // z($sendInfo); T('weixin/weixin.api'); $weixinMsgApi = new weixinMsgApi(); if ($weixinMsgApi->sendCustomMessage($sendInfo)) { return $this->JsonReturn('回复成功', null, 1); } else { return $this->JsonReturn('回复失败', array('code' => $weixinMsgApi->errCode, 'msg' => $weixinMsgApi->errMsg), 0); } }
private function _sendWXNotice(&$rs, $type = 1, $userId = 0) { if ($userId) { $steUser = D('steadmin')->where(array('user_id' => $userId))->find(); if (!$steUser) { $this->JsonReturn('抱歉,小管家不存在,请检查'); } } $msgType = 'text'; switch ($type) { case 1: //开始配货 $title = '订单【已审核】'; $desc = "社主的订单已通过审核,小管家:{$steUser['real_name']}{$steUser['phone']}【正在备货】~ 您期望的配送时间为:" . outTime($rs['arrive_date'], 2) . " {$rs['arrive_time']}。若遇上排队会需要一些时间,请耐心等待哦~"; $appDesc = "社主的订单已通过审核,小管家:{$steUser['real_name']}{$steUser['phone']}【正在备货】~ 您期望的配送时间为:" . outTime($rs['arrive_date'], 2) . " {$rs['arrive_time']}"; break; case 2: //开始配送 $title = '订单【开始配送】'; $desc = "社主的订单【开始配送】啦~ 小管家:{$steUser['real_name']}{$steUser['phone']}带着宝贝正飞奔而来,记得给小管家开门哦~"; $appDesc =& $desc; break; case 3: //配送完成 $title = '订单【完成配送】啦~ 快去写评价得红包吧~'; $desc = "亲爱哒社主大人,小管家已经将您选购的宝贝送到您的手上了。快来写个评价,跟朋友分享20个红包吧。跪谢您对结邻的支持,我们会更加努力哒~"; $appDesc = "亲爱哒社主大人,小管家已经将您选购的宝贝送到您的手上了。快来写个评价,跟朋友分享20个红包吧。"; $msgType = 'news'; break; case 4: //订单变更 $title = '订单【已变更】'; $desc = "社主的订单信息已变更,小管家:{$steUser['real_name']}{$steUser['phone']}【正在备货】~ 您期望的配送时间为:" . outTime($rs['arrive_date'], 2) . " {$rs['arrive_time']}。若遇上排队会需要一些时间,请耐心等待哦~"; $appDesc = "社主的订单信息已变更,小管家:{$steUser['real_name']}{$steUser['phone']}【正在备货】~ 您期望的配送时间为:" . outTime($rs['arrive_date'], 2) . " {$rs['arrive_time']}"; break; case 5: //异常订单恢复 $title = '异常订单【已恢复】,点击查看最新信息'; $desc = "您的异常订单:{$rs['order_sn']} 已恢复为正常订单,小管家会及时处理,请耐心等待"; $appDesc =& $desc; $msgType = 'news'; break; default: $this->JsonReturn('操作类型不正确'); } $appNoticeInfo = ''; $wxNoticeInfo = array('result' => 0, 'msg' => '未知错误'); if ($rs['order_source']) { //订单来源是App端,则改为App消息推送 $appNoticeInfo = $this->_sendAppNotice($rs, $title, $appDesc); } $touser = D('member')->getOpenidByUids($rs['uid']); if (!$rs['order_source'] && !$touser) { $this->JsonReturn('用户不存在', array('code' => '', 'msg' => ''), 0); } if ($touser) { if ($msgType == 'news') { $sendInfo = array('touser' => $touser, 'msgtype' => 'news', 'news' => array('articles' => array(array('title' => $title, 'createTime' => $rs['order_time'], 'description' => $desc, 'picurl' => '', 'url' => U('steward/order/detail', array('oid' => $rs['order_id'])))))); } else { $sendInfo = array('touser' => $touser, 'msgtype' => 'text', 'text' => array('content' => $desc . "\n <a href=\"" . U('steward/order/detail', array('oid' => $rs['order_id'])) . "\">查看订单信息</a>")); } T('weixin/weixin.api'); $weixinMsgApi = new weixinMsgApi(); if ($weixinMsgApi->sendCustomMessage($sendInfo)) { $wxNoticeInfo = array('result' => 1, 'msg' => 'ok'); } else { $wxNoticeInfo = array('result' => 0, 'msg' => $weixinMsgApi->errCode . '-' . $weixinMsgApi->errMsg); } } return $appNoticeInfo ? $appNoticeInfo : $wxNoticeInfo; }