12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- <?php
- namespace Modules\Channel\Services\WechatOpenPlatform;
- use EasyWeChat\OpenPlatform\Application;
- use Illuminate\Support\Facades\DB;
- use Modules\Common\Errors\Errors;
- use Modules\Common\Exceptions\CommonBusinessException;
- class WechatOpenPlatformService
- {
- public static function getComponentInfoByCompanyUid($companyUid) {
- $componentInfo = DB::table('wechat_open_platform_infos')
- ->where([
- 'company_uid' => $companyUid,
- 'is_enabled' => 1,
- ])->orderBy('id', 'desc')
- ->first();
- if(!$componentInfo) {
- CommonBusinessException::throwError(Errors::OPENPLATFORM_COMPANY_INFO_NOT_EXISTS);
- }
- return $componentInfo;
- }
- public static function getComponentInfoByAppid($componentAppid) {
- $componentInfo = DB::table('wechat_open_platform_infos')
- ->where([
- 'app_id' => $componentAppid,
- 'is_enabled' => 1,
- ])->orderBy('id', 'desc')
- ->first();
- if(!$componentInfo) {
- CommonBusinessException::throwError(Errors::OPENPLATFORM_COMPANY_INFO_NOT_EXISTS);
- }
- return $componentInfo;
- }
-
- public static function buildApplication($componentInfo) {
- if(!$componentInfo) {
- CommonBusinessException::throwError(Errors::OPENPLATFORM_COMPANY_INFO_NOT_EXISTS);
- }
- $config = [
- 'app_id' => $componentInfo->app_id,
- 'secret' => $componentInfo->secret,
- 'token' => $componentInfo->token,
- 'aes_key' => $componentInfo->aes_key,
- 'http' => [
- 'throw' => true,
- 'timeout' => 5.0,
- 'retry' => true,
- ],
- ];
- return new Application($config);
- }
- }
|