调用背景:ThinkPHP3.1框架WeixinModel.class.php[微信模型]
public function sendSomeFuncMsg($openid,$param,$keyword1){ $temp_text=array( "touser"=>$openid, "template_id"=>"微信模版id", "url"=>"http://".$_SERVER['HTTP_HOST'].U("Controller/action",array('param'=>$param)), "data"=>array( "first"=>array( "value"=>"标题[自定义]", "color"=>"#173177" ), "keyword1"=>array( "value"=>$keyword1, "color"=>"#173177" ), "remark"=>array( "value"=>"点击详情查看更多[自定义]", "color"=>"#173177" ) ) ); $token=$this->getToken(); $msg=urldecode(json_encode($temp_text)); $result=$this->curl->post('https://api.weixin.qq.com/cgi-bin/message/template/send?access_token='.$token,$msg); $result=json_decode($result,true); }
Tip:
url为模版消息点击后的跳转链接(用户点击,跳转前台某页面)。如果是后台(如审核操作)发送模版消息,U方法此时为后台链接,不可用。url需要根据实际情况灵活调整。