[微信公众号测试地址]([https://mp.weixin.qq.com/debug/cgi-bin/sandboxinfo?action=showinfo&t=sandbox/index](https://mp.weixin.qq.com/debug/cgi-bin/sandboxinfo?action=showinfo&t=sandbox/index))
[参考视频地址]([https://www.imooc.com/learn/618](https://www.imooc.com/learn/618))
```
\**
* 函数说明:发送模板消息
* 作者: panzhide
* 日期: 2020/7/30
* 版本: 1.0
* @param $id
* @returnstring
*/
public function send_notice(){
//1.获取到access_token
$access_token = '获取到access_token';
$url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" . $access_token;
$array = array(
'touser' => "用户openid", //用户openid
'template_id' => "在公众号下配置的模板id", //在公众号下配置的模板id
'url' => "https://www.imooc.com/course/qa/id/618/t/0?page=1", //点击模板消息会跳转的链接
'data' => array(
'first' => array('value' => "兼职平台签到测试开始", 'color' => "#FF0000"),
'keyword1' => array('value' => '兼职岗位小区门口卖西瓜', 'color' => '#FF0000'), //keyword需要与配置的模板消息对应
'keyword2' => array('value' => time(), 'color' => '#FF0000'), //keyword需要与配置的模板消息对应
'remark' => array('value' => "兼职平台签到测试结束,收到请钉钉回复一下", 'color' => "#FF0000"),
),
);
$json_template = json_encode($array);
// $res = $this->http_curl($url, 'post', 'json', $json_template);
$res = $this->curl_post($url, $json_template);
dump($res);
}
\**
* @param $url
* @param array $data
* @return mixed
* curl请求
*/
function curl\_post($url, $data = array())
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
// POST数据
curl_setopt($ch, CURLOPT_POST, 1);
// 把post的变量加上
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
```