场景
微信小程序开发
使用订阅消息
环境
thinkphp6
easywechat
代码
//发送消息通知模板
public function sendMessage($openid)
{
$config = [
'corp_id' => '',
'agent_id' => '', // 如果有 agend_id 则填写
'secret' => '',
// 指定 API 调用返回结果的类型:array(default)/collection/object/raw/自定义类名
'response_type' => 'array',
];
$data = [
'template_id' => "iGioueHodXKO8pahxSjQt3bU01Vq79JsjwTBS3YnfRU", // 所需下发的订阅模板id
'touser' => $openid, // 接收者(用户)的 openid
'page' => '', // 点击模板卡片后的跳转页面,仅限本小程序内的页面。
'data' => [ // 模板内容,格式形如 { "key1": { "value": any }, "key2": { "value": any } }
'thing3' => [
'value' => '小明', //客户名称
],
],
];
$app = Factory::miniProgram($config);
$app->subscribe_message->send($data);
}
报错信息
Request access_token fail: {"errcode":41002,"errmsg":"appid missing rid: 6263c40b-6076c953-2928c53a"}
本次问题原因
缺少app_id参数
问题分析
"errcode":41002
基本可以判断,是权限验证问题,可能的原因
1、缺少:app_id、secret
2、app_id、secret错误