|
@@ -3,19 +3,15 @@
|
|
|
namespace Modules\Channel\Http\Controllers;
|
|
|
|
|
|
use Catch\Base\CatchController;
|
|
|
-use EasyWeChat\OpenPlatform\Application;
|
|
|
use EasyWeChat\OpenPlatform\Server\Guard;
|
|
|
use Illuminate\Foundation\Validation\ValidatesRequests;
|
|
|
use Illuminate\Http\Request;
|
|
|
-use Illuminate\Support\Facades\Cache;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
-use Illuminate\Support\Facades\Redis;
|
|
|
use Modules\Channel\Models\WechatAuthorizationInfo;
|
|
|
use Modules\Channel\Services\WechatOpenPlatform\WechatOpenPlatformService;
|
|
|
use Modules\Common\Errors\Errors;
|
|
|
use Modules\Common\Exceptions\CommonBusinessException;
|
|
|
use Modules\User\Http\Controllers\UserTrait;
|
|
|
-use Symfony\Component\Cache\Adapter\RedisAdapter;
|
|
|
|
|
|
class WechatOpenPlatformController extends CatchController
|
|
|
{
|
|
@@ -35,7 +31,8 @@ class WechatOpenPlatformController extends CatchController
|
|
|
* @throws \Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface
|
|
|
* @throws \Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface
|
|
|
*/
|
|
|
- public function preauth(Request $request) {
|
|
|
+ public function preauth(Request $request)
|
|
|
+ {
|
|
|
$this->validate($request, [
|
|
|
'user_id' => 'required'
|
|
|
]);
|
|
@@ -43,7 +40,7 @@ class WechatOpenPlatformController extends CatchController
|
|
|
$componentInfo = WechatOpenPlatformService::getComponentInfoByCompanyUid($currentUser->id);
|
|
|
$app = WechatOpenPlatformService::buildApplication($componentInfo);
|
|
|
$user_id = $request->input('user_id');
|
|
|
- $url = $app->getPreAuthorizationUrl(sprintf('%s/api/channel/openPlatform/auth/%s/%s',config('app.url'), $componentInfo->app_id, $user_id), []);
|
|
|
+ $url = $app->getPreAuthorizationUrl(sprintf('%s/api/channel/openPlatform/auth/%s/%s', config('app.url'), $componentInfo->app_id, $user_id), []);
|
|
|
return $url;
|
|
|
}
|
|
|
|
|
@@ -59,7 +56,8 @@ class WechatOpenPlatformController extends CatchController
|
|
|
* @throws \Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface
|
|
|
* @throws \Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface
|
|
|
*/
|
|
|
- public function auth(Request $request, $component_appid, $user_id) {
|
|
|
+ public function auth(Request $request, $component_appid, $user_id)
|
|
|
+ {
|
|
|
$auth_code = $request->input('auth_code');
|
|
|
$auth_user = DB::table('users')
|
|
|
->where([
|
|
@@ -67,7 +65,7 @@ class WechatOpenPlatformController extends CatchController
|
|
|
])
|
|
|
->where('pid', '<>', 0)
|
|
|
->select('pid', 'id')->first();
|
|
|
- if(!$auth_user) {
|
|
|
+ if (!$auth_user) {
|
|
|
CommonBusinessException::throwError(Errors::OPENPLATFORM_OPTIMIZER_INFO_ERROR);
|
|
|
}
|
|
|
$componentInfo = WechatOpenPlatformService::getComponentInfoByAppid($component_appid);
|
|
@@ -85,16 +83,18 @@ class WechatOpenPlatformController extends CatchController
|
|
|
])->update([
|
|
|
'is_enabled' => 0,
|
|
|
]);
|
|
|
- WechatAuthorizationInfo::create([
|
|
|
+ WechatAuthorizationInfo::updateOrCreate([
|
|
|
'authorizer_appid' => $authorizer_appid,
|
|
|
'component_appid' => $component_appid,
|
|
|
'user_id' => $user_id,
|
|
|
'puser_id' => $auth_user->pid,
|
|
|
+ ], [
|
|
|
+ 'is_enabled' => 1,
|
|
|
'authorizer_refresh_token' => $authorizer_refresh_token,
|
|
|
'nick_name' => $gzhBaseInfo['authorizer_info']['nick_name'],
|
|
|
]);
|
|
|
|
|
|
- return view('wechat.openPlatform.authSuccess')->with('url', sprintf('%s/#/user/advertiser',config('app.url')));
|
|
|
+ return view('wechat.openPlatform.authSuccess')->with('url', sprintf('%s/#/user/advertiser', config('app.url')));
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -102,7 +102,8 @@ class WechatOpenPlatformController extends CatchController
|
|
|
* @param Request $request
|
|
|
* @param $component_appid
|
|
|
*/
|
|
|
- public function authorCommand(Request $request, $component_appid) {
|
|
|
+ public function authorCommand(Request $request, $component_appid)
|
|
|
+ {
|
|
|
$componentInfo = WechatOpenPlatformService::getComponentInfoByAppid($component_appid);
|
|
|
$app = WechatOpenPlatformService::buildApplication($componentInfo);
|
|
|
|
|
@@ -118,11 +119,12 @@ class WechatOpenPlatformController extends CatchController
|
|
|
return $server->serve();
|
|
|
}
|
|
|
|
|
|
- public function infoCommand(Request $request, $authorizer_appid, $component_appid) {
|
|
|
+ public function infoCommand(Request $request, $authorizer_appid, $component_appid)
|
|
|
+ {
|
|
|
|
|
|
$componentInfo = WechatOpenPlatformService::getComponentInfoByAppid($component_appid);
|
|
|
$app = WechatOpenPlatformService::buildApplication($componentInfo);
|
|
|
- myLog("wx-xiaoxi")->info('-------开始处理---'.get_date());
|
|
|
+ myLog("wx-xiaoxi")->info('-------开始处理---' . get_date());
|
|
|
$server = $app->getServer();
|
|
|
$message = $server->getDecryptedMessage();
|
|
|
myLog("wx-xiaoxi")->info([
|
|
@@ -131,17 +133,18 @@ class WechatOpenPlatformController extends CatchController
|
|
|
'param' => $request->all(),
|
|
|
'msg' => $message,
|
|
|
]);
|
|
|
- $refreshToken = WechatOpenPlatformService::getRefreshToken($authorizer_appid,$component_appid);
|
|
|
+ $refreshToken = WechatOpenPlatformService::getRefreshToken($authorizer_appid, $component_appid);
|
|
|
$server = $app->getOfficialAccountWithRefreshToken($authorizer_appid, $refreshToken)->getServer();
|
|
|
- $server->addMessageListener('text', function($message) {
|
|
|
+ $server->addMessageListener('text', function ($message) {
|
|
|
myLog("wx-xiaoxi")->info('----文本消息---');
|
|
|
- if ($message->Content == "pk"){
|
|
|
- return $message->FromUserName;
|
|
|
+ if ($message->Content == "pk") {
|
|
|
+ return $message->FromUserName;
|
|
|
}
|
|
|
});
|
|
|
|
|
|
- $server->addEventListener('subscribe', function() { });
|
|
|
- myLog("wx-xiaoxi")->info('-------结束处理---'.get_date());
|
|
|
+ $server->addEventListener('subscribe', function () {
|
|
|
+ });
|
|
|
+ myLog("wx-xiaoxi")->info('-------结束处理---' . get_date());
|
|
|
return $server->serve();
|
|
|
}
|
|
|
}
|