public function action_order_create() { $params = ['first' => ['value' => '订单支付成功', 'color' => '#D02090'], 'keyword1' => ['value' => date('YmdHis'), 'color' => '#D02090'], 'keyword2' => ['value' => '菊花茶,西湖龙井,豪华果盘,精品果盘,百威,哈尔滨啤酒,威尔士香槟', 'color' => '#D02090'], 'keyword3' => ['value' => 100, 'color' => '#D02090'], 'remark' => ['value' => '点击查看订单已使用状态', 'color' => '#D02090']]; $account = \Model_WXAccount::find(1); $to_openid = 'oqTo9uJao4vdZy5EZH8yQgL_0SY0'; $tmpl_id = 'tQ46mymM617VOKpNv6rbg5hBQpXIle8EC64n-ozbSSw'; $tmpl = new \handler\mp\TemplateMsg($account, $to_openid, $tmpl_id, 'http://www.baidu.com'); $result = $tmpl->send($params); if ($result->errcode != 0) { die('模板消息发送失败'); } die('消息发送成功'); }
/** * 发送模板消息 * * @param $no 订单号 * @param $title 订单标题 * @param $total_fee 订单金额 * @param $url 订单链接 * @return bool */ private function sendMsgTemplate($tmpl_id, $params, $url) { $seller = \Session::get('seller', false); if (!$seller || isset($seller->is_send_template_msg) && !$seller->is_send_template_msg) { $this->result_message = '商户未设置发送微信模板消息!'; return false; } $account = \Session::get('WXAccount', false); $to_openid = $this->getParentWechatOpenid(); $tmpl = new \handler\mp\TemplateMsg($account, $to_openid, $tmpl_id, $url); $result = $tmpl->send($params); if ($result->errcode != 0) { $this->result_message = '消息发送失败!'; return false; } }