首先说明,我是在开发工具环境下运行的,获取得到的formId为:“the formId is a mock one”。继续:
获取access_token
发送模板消息
访问接口地址:https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET,
得到token:
array(2) {
["access_token"]=>
string(138) "iqHh-ixElcCeBQf6KpYiJ0-oSRkl3WUskKNlHS1fptHSDQ0wfJTw8hGJWVwtLNefXl0Jtq1r8dy70pOWwg4EOcH3GOrIEVZfrNDLvGoUarOlYoulN16VfEuTdv-JW0a1OYOaAEARBR"
["expires_in"]=>
int(7200)
}
访问接口地址:https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=ACCESS_TOKEN
POST数据为:
$data = array ("touser" => $oid,
"template_id" => "l54PVNXqYmp1rUDh4oPgFvGS5WThK2oN2rL20ztQYg",
"form_id" => $fid,
"data" => array ("keyword1" => array ( "value" => $name ),
"keyword2" => array ( "value" => $gender ),
"keyword3" => array ( "value" => date() )
)
);
但是返回的数据貌似是又一次获取了access_token:
array(2) {
["access_token"]=>
string(138) "iqHh-ixElcCeBQf6KpYiJ0-oSRkl3WUskKNlHS1fptGmAFDUiNAawF6uUE36YPh2AWejLYyEGYMkNFTAZIKPmoLSLwQcLQWDxkDZluLoWmJKzF_0yIr3DqCqmiMNuhGrQCSaAEAKWM"
["expires_in"]=>
int(7198)
}
怎么回事泥?(怎么没有“模板消息”标签??)