12345678910111213141516171819202122232425262728293031323334 |
- <?php
- namespace App\Http\Utils;
- use App\Exceptions\CommonException;
- use App\Http\Enum\ErrorEnum;
- use App\Models\WechatAccountModel;
- use EasyWeChat\Factory;
- class WechatAccountUtil extends BaseUtil
- {
- /**
- * @param $code 公众号code码
- * @return \EasyWeChat\OfficialAccount\Application
- * @throws CommonException
- */
- public static function getApp($code)
- {
- $wechatAccount = WechatAccountModel::findByWechatAppCode($code);
- if(!$wechatAccount){
- throw new CommonException(ErrorEnum::ERROR_ACCOUNT_EXIST);
- }
- $config = [
- "app_id"=>$wechatAccount->wechat_app_id,
- "secret"=>$wechatAccount->wechat_app_secret,
- "response_type"=>"array",
- "token"=>$wechatAccount->wechat_app_token,
- "aes_key"=>$wechatAccount->wechat_app_aes_key
- ];
- return Factory::officialAccount($config);
- }
- }
|