public function message_tpl($openid,$template_id,$jump_url,$tpl_data){
$tokenInfo = $this->getAccessToken();
if($tokenInfo['access_token']){
$token = $tokenInfo['access_token'];
}else{
exit('accesstoken error');
}
$url = 'https://api.weixin.qq.com/cgi-bin/message/template/send?access_token='.$token;
$params = array(
'touser' => $openid,
'template_id' => $template_id,
'url' => $jump_url,
'data' => $tpl_data,
);
$params = json_encode($params);
$res = Http::post($url,$params);
return $res;
}
public function getAccessToken(){
$wechat = Config::get('site.wechat');
$appid = $wechat['app_id'];
$secret = $wechat['app_secret'];
$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$secret;
$response = Http::get($url);
$ret = (array)json_decode($response, true);
return $ret ? $ret : [];
}
//dada
'data' => array(
'first' => array('value' => $tpl_data['first']),
'keyword1' => array('value' => $tpl_data['keyword1']),
'keyword2' => array('value' => $tpl_data['keyword2']),
'keyword3' => array('value' => $tpl_data['keyword3']),
'keyword4' => array('value' => $tpl_data['keyword4']),
'remark' => array('value' => $tpl_data['remark'])
)
微信公众号模板消息api
最新推荐文章于 2024-08-17 11:27:47 发布