|
@@ -3,7 +3,9 @@
|
|
|
namespace Modules\WechatPlatform\Http\Controllers;
|
|
|
|
|
|
use Catch\Base\CatchController;
|
|
|
+use Exception;
|
|
|
use Illuminate\Http\Request;
|
|
|
+use Modules\Channel\Services\WechatOpenPlatform\WechatOpenPlatformService;
|
|
|
use Modules\User\Http\Controllers\UserTrait;
|
|
|
use Modules\WechatPlatform\Models\WechatAuthorizationInfo;
|
|
|
|
|
@@ -20,6 +22,8 @@ class WechatAuthorizationInfoController extends CatchController
|
|
|
public function index(Request $request)
|
|
|
{
|
|
|
|
|
|
+ $page_size = $request->get('limit', 20);
|
|
|
+
|
|
|
if($this->isOptimizer()){
|
|
|
$where = [
|
|
|
['wechat_authorization_infos.user_id','=',$this->getLoginUserId()],
|
|
@@ -34,16 +38,38 @@ class WechatAuthorizationInfoController extends CatchController
|
|
|
return [];
|
|
|
}
|
|
|
|
|
|
+ $nick_name = $request->get('nick_name');
|
|
|
+ if($nick_name){
|
|
|
+ $where[] = ['wechat_authorization_infos.nick_name','like',"%s".$nick_name."%"];
|
|
|
+ }
|
|
|
+
|
|
|
$result = $this->wechatAuthorizationInfo->where($where)
|
|
|
->join('wechat_open_platform_infos','wechat_open_platform_infos.app_id','=','wechat_authorization_infos.component_appid')
|
|
|
->join('miniprogram','wechat_open_platform_infos.xcx_appid','=','miniprogram.appid')
|
|
|
- ->select('wechat_authorization_infos.nick_name','wechat_authorization_infos.authorizer_appid','miniprogram.name as xcx_name')
|
|
|
- ->paginate($request->input('limit', 20));
|
|
|
+ ->select('wechat_authorization_infos.nick_name','wechat_authorization_infos.authorizer_appid','miniprogram.name as xcx_name','wechat_authorization_infos.authorizer_refresh_token'
|
|
|
+ ,'wechat_open_platform_infos.app_id','wechat_open_platform_infos.secret','wechat_open_platform_infos.token','wechat_open_platform_infos.aes_key')
|
|
|
+ ->paginate($page_size);
|
|
|
|
|
|
|
|
|
foreach($result as $item){
|
|
|
- //获取粉丝数
|
|
|
- $item->fans_count = 100;
|
|
|
+ //todo 获取粉丝数
|
|
|
+ $item->fans_count = 0;
|
|
|
+ $application = WechatOpenPlatformService::buildApplication($item);
|
|
|
+ try{
|
|
|
+ $officialAccount = $application->getOfficialAccountWithRefreshToken($item->authorizer_appid, $item->authorizer_refresh_token);
|
|
|
+ $api = $officialAccount->getClient();
|
|
|
+ $response = $api->get('/cgi-bin/user/list', []);
|
|
|
+ if($response->isSuccessful()){
|
|
|
+ $item->fans_count = $response['total'];
|
|
|
+ }
|
|
|
+ }catch(Exception $e){
|
|
|
+ myLog('WechatAuthorizationInfo')->error($e);
|
|
|
+ }
|
|
|
+ unset($item->authorizer_refresh_token);
|
|
|
+ unset($item->secret);
|
|
|
+ unset($item->token);
|
|
|
+ unset($item->aes_key);
|
|
|
+ unset($item->app_id);
|
|
|
}
|
|
|
|
|
|
return $result;
|