123456789101112131415161718192021222324252627282930313233343536373839404142 |
- <?php
- namespace Modules\Channel\Http\Controllers;
- use Catch\Base\CatchController;
- use EasyWeChat\OpenPlatform\Application;
- use Illuminate\Http\Request;
- use Modules\Channel\Services\WechatOpenPlatform\WechatOpenPlatformService;
- use Modules\Common\Errors\Errors;
- use Modules\Common\Exceptions\CommonBusinessException;
- use Modules\User\Http\Controllers\UserTrait;
- class WechatOpenPlatformController extends CatchController
- {
- use UserTrait;
- // 授权跳转页
- public function preauth(Request $request) {
- $currentUser = $this->getCurrentUser();
- $componentInfo = WechatOpenPlatformService::getComponentInfo($currentUser->pid);
- if(!$componentInfo) {
- CommonBusinessException::throwError(Errors::OPENPLATFORM_COMPANY_INFO_NOT_EXISTS);
- }
- $config = [
- 'app_id' => $componentInfo->app_id, // 开放平台账号的 appid
- 'secret' => $componentInfo->secret, // 开放平台账号的 secret
- 'token' => $componentInfo->token, // 开放平台账号的 token
- 'aes_key' => $componentInfo->aes_key, // 明文模式请勿填写 EncodingAESKey
- 'http' => [
- 'throw' => true, // 状态码非 200、300 时是否抛出异常,默认为开启
- 'timeout' => 5.0,
- 'retry' => true, // 使用默认重试配置
- ],
- ];
- $app = new Application($config);
- $url = $app->createPreAuthorizationUrl(url('/api/channel/openPlatform/auth/'.$componentInfo->app_id), []);
- return $url;
- }
- public function auth(Request $request, $component_appid) {
- }
- }
|