coupon-admin/app/service/wx/WechatApplets.php

48 lines
1.2 KiB
PHP

<?php
namespace app\service\wx;
use EasyWeChat\Factory;
use EasyWeChat\MiniProgram\Application;
use think\facade\Config;
/**
* 微信小程序
* Class WechatApplets
* @package app\service\wx
*/
class WechatApplets
{
private static $app = null;
/**
* TODO 正式上线时需要替换模板配置信息和相关小程序配置信息
*/
// 订阅消息模板:预约通知
public const SUBSCRIBE_TPL_APPOINTMENT = 'uvGd7RqaegheGU-uVxR-uM3y2MadZeMOHdQaNiiWm8U';
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['applets_appId'],
'secret' => $conf['applets_appSecret'],
// 返回数据类型 array | xml
'response_type' => 'array',
];
self::$app = Factory::miniProgram($config);
}
return self::$app;
}
}