public function sendtpl($openid, $url, $template_id, $content) { global $_GPC, $_W; load()->classs('weixin.account'); load()->func('communication'); $obj = new WeiXinAccount(); $access_token = $obj->fetch_available_token(); $data = array('touser' => $openid, 'template_id' => $template_id, 'url' => $url, 'topcolor' => "#FF0000", 'data' => $content); $json = json_encode($data); $url = 'https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=' . $access_token; $ret = ihttp_post($url, $json); }
//查小区编号 $member = $this->changemember(); $data = array('weid' => $_W['uniacid'], 'regionid' => $member['regionid'], 'title' => $_GPC['title'], 'createtime' => $_W['timestamp'], 'status' => $_GPC['status'], 'enable' => $_GPC['enable'], 'datetime' => $_GPC['datetime'], 'location' => $_GPC['location'], 'reason' => $_GPC['reason'], 'remark' => $_GPC['remark']); if (checksubmit('submit')) { if (empty($id)) { pdo_insert("xcommunity_announcement", $data); $id = pdo_insertid(); } else { pdo_update("xcommunity_announcement", $data, array('id' => $id, 'weid' => $_W['weid'])); } //是否启用模板消息 if ($_GPC['status'] == 2) { load()->classs('weixin.account'); load()->func('communication'); $obj = new WeiXinAccount(); $access_token = $obj->fetch_available_token(); $templates = pdo_fetch("SELECT * FROM" . tablename('xcommunity_notice_setting') . "WHERE uniacid='{$_W['uniacid']}'"); $key = 'template_id_' . $_GPC['enable']; $template_id = $templates[$key]; $openids = pdo_fetchall("SELECT openid FROM" . tablename('xcommunity_member') . "WHERE weid='{$_W['uniacid']}' AND regionid='{$member['regionid']}'"); $url = $_W['siteroot'] . "app/index.php?i={$_W['uniacid']}&c=entry&id={$id}&op=detail&do=announcement&m=xfeng_community"; foreach ($openids as $key => $value) { $data = array('touser' => $value['openid'], 'template_id' => $template_id, 'url' => $url, 'topcolor' => "#FF0000", 'data' => array('first' => array('value' => $_GPC['title']), 'time' => array('value' => $_GPC['datetime']), 'location' => array('value' => $_GPC['location']), 'reason' => array('value' => $_GPC['reason']), 'remark' => array('value' => $_GPC['remark']))); $json = json_encode($data); $url = 'https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=' . $access_token; $ret = ihttp_post($url, $json); } } message('提交成功', $this->createMobileUrl('announcement', array('op' => 'display')), 'success'); } } elseif ($op == 'verify') {
private function destroy_card($content) { // 获取公众号的 access_token load()->classs('weixin.account'); $access_token = WeiXinAccount::fetch_available_token(); // 生成post请求的url地址 $url = 'https://api.weixin.qq.com/card/code/consume?access_token=' . $access_token; // post请求的内容 $posts = '{"code":' . $content . '}'; // 加载文件: load()→func('communication') load()->func('communication'); // 向处理卡券的模块提交post请求,并返回数据,可以尝试对结果打印 $result = ihttp_post($url, $posts); // print_r($result); // 对返回的数据中的['content']进行json_decode处理 $res = json_decode($result['content'], true); // 获取返回的错误码 $errcode = $res["errcode"]; // 获取返回的card_id $card_id = $res["card_id"]; // 根据返回的错误码进行相应的处理 switch ($errcode) { case '0': $message = '消费成功!卡券信息为:' . $this->reply_kaquanDetail($card_id); break; case '40099': $message = '该卡券已经被销毁!请重新输入' . $str . '进行销卡'; break; case '40078': $message = '不合法的卡券状态!请重新输入“销卡”进行销卡'; break; default: $message = '出现错误,无法销毁!请重新输入“销卡”进行销卡'; break; } $this->endContext(); // 返回消息内容 return $this->respText($message); }