在我们进行选择个人类型订阅号时,因为没有经过认证,所以该公众号并不能实现某些接口,比如自定义菜单,带参数二维码的实现,获取用户列表信息等;这时我们就可以选择 开发-》开发者工具-》公众平台测试账号,扫码进行登陆,在我们使用code来获取access_token时,有时候会出现40163错误,即是code has been used,这时我们需要openid进行模板消息的发送,可以使用
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' => 'template_id',
'url' => 'https://www.360kan.com/dianying/index.html',
'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);
var_dump($res);
}
这时我们可以在测试号的用户列表中找到openid,以及设置模板接口自动生成的template_id。