caipan_shop_admin/app/service/wx/Wechat.php

46 lines
987 B
PHP
Executable File
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?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;
}
}