EasyWechat 使用

目录

 公众号素材上传

公众号的模板消息

小程序二维码生成

 小程序订阅消息

前端授权


 公众号素材上传

        $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)
    }
})

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值