course/app/common/service/WechatSubscriptService.php
2024-08-04 22:28:52 +08:00

44 lines
1.0 KiB
PHP

<?php
namespace app\common\service;
use app\constant\ResponseCode;
use app\utils\WechatUtil;
use GuzzleHttp\Client;
use support\Cache;
use think\Exception;
/**
* 微信公众号
*/
class WechatSubscriptService
{
const SUBSCRIPT_ACCESS_TOKEN = 'subscript_access_token';
protected $client;
public function __construct()
{
$this->client = new Client(['base_uri' => 'https://api.weixin.qq.com']);
}
/**
* @desc 发送公众号消息
* @param $send_data
* @return void
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function sendMsg($send_data)
{
$access_token = WechatUtil::getAccessToken();
print '<pre>';
print_r($access_token);
die;
$result = $this->client->request('post', 'cgi-bin/message/template/send?access_token=' . $access_token, [
'json' => $send_data,
]);
$result = json_decode($result->getBody()->getContents(), true);
raw_log('wechat/send_msg', ['send_data'=>$send_data, 'result'=>$result]);
}
}