first commit
This commit is contained in:
38
modules/Wechat/app/Services/MessageService.php
Normal file
38
modules/Wechat/app/Services/MessageService.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace Modules\Wechat\Services;
|
||||
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use EasyWeChat\OfficialAccount\Application;
|
||||
|
||||
class MessageService {
|
||||
/**
|
||||
* 发送模板消息
|
||||
* @param $openid
|
||||
* @param $template_id
|
||||
* @param $url
|
||||
* @param $data
|
||||
* @return mixed
|
||||
*/
|
||||
public function sendMessage($openid, $template_id, $url, $data){
|
||||
$config = Config::get('wechat.wx');
|
||||
$app = new Application($config);
|
||||
$client = $app->getClient();
|
||||
|
||||
$result = $client->postJson('/cgi-bin/message/template/send', [
|
||||
'touser' => $openid,
|
||||
'template_id' => $template_id,
|
||||
'page' => $url,
|
||||
'data' => $data,
|
||||
'miniprogram_state' => 'formal',
|
||||
'lang' => 'zh_CN',
|
||||
]);
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user