luck-draw/app/service/wx/Wechat.php

46 lines
987 B
PHP
Raw Normal View History

2022-02-22 09:27:27 +00:00
<?php
namespace app\service\wx;
use EasyWeChat\Factory;
use EasyWeChat\OfficialAccount\Application;
use think\facade\Config;
/**
* 微信公众号
* Class Wechat
* @package app\service\wx
*/
class Wechat
{
private static $app = null;
private function __construct()
{
}
private function __clone()
{
}
//微信实例 单例模式
public static function getInstance(): ?Application
{
if (self::$app == null) {
Config::load('extra/wechat', 'wechat');
$conf = config('wechat');
$config = [
'app_id' => $conf['appId'],
'secret' => $conf['appSecret'],
// 指定 API 调用返回结果的类型array(default)/collection/object/raw/自定义类名
'response_type' => 'array',
//...
];
self::$app = Factory::officialAccount($config);
}
return self::$app;
}
}