一、实现步骤
1、在测试公众号添加模板
2、代码实现:
//模板消息接口
public function sendTemplateMsg(){
//1、获取access_token
$access_token = $this -> getWxAccessToken();
$url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=".$access_token;
//2、组装数组
$array = array(
'touser' => '填写微信openid',
'template_id' => '模板id',
'url' => 'http://www.baidu.com',
'data' => array(
'name' => array('value' => 'hello', 'color' => "#173177"),
'money' => array('value' => '100', 'color' => "#173177"),
'date' => array('value' => date('Y-m-d H:i:s'),'color' => "#173177")
),
);
//3、将array->json
$postJson = json_encode($array);
echo '<hr />';
//4、调用curl
$res = $this->http_curl($url,'post','json',$postJson);
}
还不快抢沙发