更新
This commit is contained in:
@@ -4,15 +4,13 @@ declare(strict_types=1);
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\common\service\qywx\QywxPromotionOpenWorkService;
|
||||
use app\common\service\qywx\QywxPromotionRedirectService;
|
||||
use think\facade\Log;
|
||||
|
||||
/** 企业微信推广公开端点:服务商回调、授权回跳、JS 与随机跳转。 */
|
||||
/** 企业微信获客助手公开端点:JS 与随机跳转。 */
|
||||
class QywxPromotionPublicController extends BaseApiController
|
||||
{
|
||||
/** 公开安装代码、随机跳转与企业微信服务商回调均不依赖前台用户登录。 */
|
||||
public array $notNeedLogin = ['script', 'redirect', 'providerCallback', 'authCallback'];
|
||||
/** 公开安装代码与随机跳转不依赖前台用户登录。 */
|
||||
public array $notNeedLogin = ['script', 'redirect'];
|
||||
|
||||
public function script(string $key)
|
||||
{
|
||||
@@ -58,7 +56,7 @@ JS;
|
||||
'ip' => (string) $this->request->ip(),
|
||||
]);
|
||||
if (!$picked) {
|
||||
return response('当前暂无可用的企业微信推广链接,请稍后再试。', 503, [
|
||||
return response('当前暂无可用的企业微信获客助手链接,请稍后再试。', 503, [
|
||||
'Content-Type' => 'text/plain; charset=utf-8',
|
||||
'Cache-Control' => 'no-store',
|
||||
]);
|
||||
@@ -70,40 +68,4 @@ JS;
|
||||
]);
|
||||
}
|
||||
|
||||
public function providerCallback()
|
||||
{
|
||||
try {
|
||||
$psr = QywxPromotionOpenWorkService::serveProviderCallback();
|
||||
$body = $psr->getBody();
|
||||
$body->rewind();
|
||||
$headers = [];
|
||||
if ($psr->getHeaderLine('Content-Type') !== '') {
|
||||
$headers['Content-Type'] = $psr->getHeaderLine('Content-Type');
|
||||
}
|
||||
|
||||
return response($body->getContents(), $psr->getStatusCode(), $headers);
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('企微推广服务商回调失败:' . $e->getMessage(), ['exception' => $e]);
|
||||
|
||||
return response('error', 500, ['Content-Type' => 'text/plain; charset=utf-8']);
|
||||
}
|
||||
}
|
||||
|
||||
public function authCallback()
|
||||
{
|
||||
$fallback = rtrim($this->request->domain(), '/') . '/admin/first_visit/wecom_promotion';
|
||||
$returnUrl = QywxPromotionOpenWorkService::configuredAdminReturnUrl($fallback);
|
||||
try {
|
||||
$result = QywxPromotionOpenWorkService::consumeAuthorizationCallback(
|
||||
trim((string) $this->request->get('auth_code', '')),
|
||||
trim((string) $this->request->get('state', ''))
|
||||
);
|
||||
$query = ['wecom_auth' => 'success', 'account_id' => (int) $result['id']];
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('企微推广授权回跳失败:' . $e->getMessage(), ['exception' => $e]);
|
||||
$query = ['wecom_auth' => 'failed', 'message' => mb_substr($e->getMessage(), 0, 160)];
|
||||
}
|
||||
|
||||
return redirect($returnUrl . (str_contains($returnUrl, '?') ? '&' : '?') . http_build_query($query), 302);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user