目录
公众号素材上传
$config = [
'app_id' => 'APPID',
'secret' => '密钥',
'response_type' => 'array',
];
$app = Factory::officialAccount($config);
$result = $app->material->uploadImage("uploads/图片地址.png");
公众号的模板消息
$config = [
'app_id' => '你的公众号appid',
'secret' => '你的公众号secret',
];
$app = Factory::officialAccount($config);
$app->template_message->send([
'touser' => '用户openId',
'template_id' => '您的模板id',
'url' => 'https://easywechat.org', //选填
'data' => [
'first' => ['您有新的订单订单号:123456', '#FF0000'],
'keyword1' => '测试',
'keyword2' => '测试',
'keyword3' => '测试',
'keyword4' => '测试',
'keyword5' => '测试',
'keyword6' => '测试',
'keyword7' => ['测试', '#FF0000'],
'remark' => ['测试', '#00FF00'],
],
]);
小程序二维码生成
$config = [
'app_id' => $appid,
'secret' => $key,
];
$app = Factory::miniProgram($config);
$response = $app->app_code->get('pages/index/index?id=参数', [
'width' => 150,
'line_color' => [
'r' => 0,
'g' => 186,
'b' => 173,
],
]);
if ($response instanceof \EasyWeChat\Kernel\Http\StreamResponse) {
//二维码保存
$filename = $response->saveAs('qrcode', '123.png');
}
return json('生成成功');
小程序订阅消息
$config = [
'app_id' => '小程序APPID',
'secret' => '小程序secret',
];
$app = Factory::miniProgram($config);
$data = [
'template_id' =>'订阅消息ID',
'touser' => '用户openid',
'page' => '',
'data' => [
'character_string1' =>123,
'thing2' => '测试',
'amount4' => 90,
'thing5' => '测试',
'time17' => date('Y-m-d'),
],
];
return json( $app->subscribe_message->send($data));
前端授权
wx.requestSubscribeMessage({
tmplIds: ['订阅消息ID','可以多写几个'],
success(res) {
console.log(res)
}
})