微信模板消息发送errcode:40003 invalid openid rid?
$appid = "********"; //填写微信后台的appid
$appsecret = "************"; //填写微信后台的appsecret
$TOKEN_URL = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $appid . "&secret=" . $appsecret;
$json = file_get_contents($TOKEN_URL);
$result = json_decode($json, true);
$ACCESS_TOKEN = $result['access_token'];
$template = array(
'touser' => '************',
'template_id' => "********", //模板的id
'url' => "http://weixin.qq.com/download",
'topcolor' => "#FF0000",
'data' => array(
'first' => array('value' => urlencode('first'), 'color' => "#00008B"), //函数传参过来的name
'店名' => array('value' => urlencode('店名'), 'color' => '#00008B'), //函数传参过来的zu
'销售额' => array('value' => urlencode('销售额'), 'color' => '#00008B'), //时间
'客单数' => array('value' => urlencode('客单数'), 'color' => '#00008B'),
'remain' => array('value' => urlencode('remain'), 'color' => '#00008B'),//函数传参过来的ramain
)
);
$json_template = json_encode($template);
$url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" . $ACCESS_TOKEN;
$res = $this->http_request($url, urldecode($json_template));
if ($res['errcode'] == 0) echo '消息发送成功!';