WechatOpenPlatformController.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. namespace Modules\Channel\Http\Controllers;
  3. use Catch\Base\CatchController;
  4. use EasyWeChat\OpenPlatform\Application;
  5. use Illuminate\Http\Request;
  6. use Modules\Channel\Services\WechatOpenPlatform\WechatOpenPlatformService;
  7. use Modules\Common\Errors\Errors;
  8. use Modules\Common\Exceptions\CommonBusinessException;
  9. use Modules\User\Http\Controllers\UserTrait;
  10. class WechatOpenPlatformController extends CatchController
  11. {
  12. use UserTrait;
  13. // 授权跳转页
  14. public function preauth(Request $request) {
  15. $currentUser = $this->getCurrentUser();
  16. $componentInfo = WechatOpenPlatformService::getComponentInfo($currentUser->pid);
  17. if(!$componentInfo) {
  18. CommonBusinessException::throwError(Errors::OPENPLATFORM_COMPANY_INFO_NOT_EXISTS);
  19. }
  20. $config = [
  21. 'app_id' => $componentInfo->app_id, // 开放平台账号的 appid
  22. 'secret' => $componentInfo->secret, // 开放平台账号的 secret
  23. 'token' => $componentInfo->token, // 开放平台账号的 token
  24. 'aes_key' => $componentInfo->aes_key, // 明文模式请勿填写 EncodingAESKey
  25. 'http' => [
  26. 'throw' => true, // 状态码非 200、300 时是否抛出异常,默认为开启
  27. 'timeout' => 5.0,
  28. 'retry' => true, // 使用默认重试配置
  29. ],
  30. ];
  31. $app = new Application($config);
  32. $url = $app->createPreAuthorizationUrl(url('/api/channel/openPlatform/auth/'.$componentInfo->app_id), []);
  33. return $url;
  34. }
  35. public function auth(Request $request, $component_appid) {
  36. }
  37. }