[微信公眾號測試地址]([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;
????}
```