123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587 |
- <?php
- namespace App\Http\Controllers\Wechat\OfficialAccount;
- use App\Http\Controllers\Channel\BaseController as ChannelBaseController;
- use App\Modules\OfficialAccount\Services\OfficialAccountService;
- use App\Modules\OfficialAccount\Models\OfficialAccount;
- use App\Modules\OfficialAccount\Models\ForceSubscribeUsers;
- use App\Http\Controllers\Wechat\OfficialAccount\Transformers\OfficialAccountTransformer;
- use Illuminate\Http\Request;
- use GuzzleHttp\Client;
- use App\Libs\OSS;
- class OfficialAccountsController extends ChannelBaseController
- {
-
-
- function officialAccountByAppid(Request $request)
- {
- $appid = $request->has('appid') ? $request->input('appid') : '';
- \Log::info('==========================进入officialAccountByAppid方法'.$appid);
- if(empty($appid)) {
- return response()->error("PARAM_EMPTY");
- }
- $officialAccount['appid'] = $appid;
- $officialAccountService = OfficialAccountService::officialAccountByAppid($officialAccount);
- return response()->item(new OfficialAccountTransformer(), $officialAccountService);
- }
-
- function canUseOfficialAccountByChannelId(Request $request)
- {
- $distribution_channel_id = $request->has('distribution_channel_id') ? $request->input('distribution_channel_id') : '';
- if(empty($distribution_channel_id)) {
- return response()->error("PARAM_EMPTY");
- }
- $officialAccount['distribution_channel_id'] = $distribution_channel_id;
- $officialAccountService = OfficialAccountService::canUseOfficialAccountByChannelId($officialAccount);
-
- return response()->item(new OfficialAccountTransformer(), $officialAccountService);
- }
-
-
- function officialAuthAccountBydistributionChannelId(Request $request)
- {
- $distribution_channel_id = $request->has('distribution_channel_id') ? $request->input('distribution_channel_id') : '';
- if(empty($distribution_channel_id)) {
- return response()->error("PARAM_EMPTY");
- }
- $officialAccount['distribution_channel_id'] = $distribution_channel_id;
- $officialAccountService = OfficialAccountService::officialAuthAccountBydistributionChannelId($officialAccount);
- return response()->collection(new OfficialAccountTransformer(), $officialAccountService);
- }
-
- function allOfficialAccountBydistributionChannelId(Request $request)
- {
- $distribution_channel_id = $request->has('distribution_channel_id') ? $request->input('distribution_channel_id') : '';
- if(empty($distribution_channel_id)) {
- return response()->error("PARAM_EMPTY");
- }
- $officialAccount['distribution_channel_id'] = $distribution_channel_id;
- $officialAccountService = OfficialAccountService::allOfficialAccountBydistributionChannelId($officialAccount);
-
- return response()->collection(new OfficialAccountTransformer(), $officialAccountService);
- }
-
- function authOfficialAccount(Request $request) {
- $appid = $request->has('appid') ? $request->input('appid') : '';
-
-
- $distribution_channel_id = $request->has('distribution_channel_id') ? $request->input('distribution_channel_id') : '';
-
- $appsecret = $request->has('appsecret') ? $request->input('appsecret') : '';
-
- $alias = $request->has('alias') ? $request->input('alias') : '';
-
- $name = $request->has('name') ? $request->input('name') : '';
-
- $nickname = $request->has('nickname') ? $request->input('nickname') : '';
-
- $head_img = $request->has('head_img') ? $request->input('head_img') : '';
-
- $qrcode_url = $request->has('qrcode_url') ? $request->input('qrcode_url') : '';
-
- $principal_name = $request->has('principal_name') ? $request->input('principal_name') : '';
-
- $service_type_info = $request->has('service_type_info') ? $request->input('service_type_info') : '';
-
- $func_info = $request->has('func_info') ? $request->input('func_info') : '';
-
- $authorizer_refresh_token = $request->has('authorizer_refresh_token') ? $request->input('authorizer_refresh_token') : '';
-
- $is_auth = $request->has('is_auth') ? $request->input('is_auth') : '1';
-
- $official_account_type = $request->has('official_account_type') ? $request->input('official_account_type') : '';
-
- $is_enabled = 1;
- $verify_txt = $request->has('verify_txt') ? $request->input('verify_txt') : '';
- $officialAccount['appid'] = $appid;
- $officialAccount['distribution_channel_id'] = $distribution_channel_id;
- $officialAccount['appsecret'] = $appsecret;
- $officialAccount['alias'] = $alias;
- $officialAccount['name'] = $name;
- $officialAccount['nickname'] = $nickname;
- $officialAccount['head_img'] = $head_img;
- $officialAccount['qrcode_url'] = $qrcode_url;
- $officialAccount['principal_name'] = $principal_name;
- $officialAccount['service_type_info'] = $service_type_info;
- $officialAccount['func_info'] = $func_info;
- $officialAccount['authorizer_refresh_token'] = $authorizer_refresh_token;
- $officialAccount['is_auth'] = $is_auth;
- $officialAccount['official_account_type'] = $official_account_type;
- $officialAccount['is_enabled'] = $is_enabled;
- $officialAccount['verify_txt'] = $verify_txt;
- \Log::info($appid.':auth:create:params');
- \Log::info($officialAccount);
- $resultStatus = OfficialAccountService::authOfficialAccount($officialAccount);
- if ($resultStatus == 1) {
- return response()->success();
- }elseif ($resultStatus == 2) {
- return response()->error('OFFICIAL_ACCOUNT_IS_EXIST');
- }elseif ($resultStatus == 0) {
- return response()->error('OFFICIAL_ACCOUNT_FAILED');
- }else{
- return response()->error('OFFICIAL_ACCOUNT_FAILED');
- }
- }
-
- function updateOfficialAccount(Request $request) {
- $appid = $request->has('appid') ? $request->input('appid') : '';
-
- $distribution_channel_id = $request->has('distribution_channel_id') ? $request->input('distribution_channel_id') : '';
-
-
- $appsecret = $request->has('appsecret') ? $request->input('appsecret') : '';
-
- $alias = $request->has('alias') ? $request->input('alias') : '';
-
- $name = $request->has('name') ? $request->input('name') : '';
-
- $nickname = $request->has('nickname') ? $request->input('nickname') : '';
-
- $head_img = $request->has('head_img') ? $request->input('head_img') : '';
-
- $qrcode_url = $request->has('qrcode_url') ? $request->input('qrcode_url') : '';
-
- $principal_name = $request->has('principal_name') ? $request->input('principal_name') : '';
-
- $service_type_info = $request->has('service_type_info') ? $request->input('service_type_info') : '';
-
- $func_info = $request->has('func_info') ? $request->input('func_info') : '';
-
- $authorizer_refresh_token = $request->has('authorizer_refresh_token') ? $request->input('authorizer_refresh_token') : '';
-
- $is_auth = $request->has('is_auth') ? $request->input('is_auth') : '1';
-
- $official_account_type = $request->has('official_account_type') ? $request->input('official_account_type') : '';
-
- $is_enabled = 1;
- $verify_txt = $request->has('verify_txt') ? $request->input('verify_txt') : '';
- $subscribe_top_num = $request->has('subscribe_top_num') ? $request->input('subscribe_top_num') : '';
- $subscribe_day_maximum = $request->has('subscribe_day_maximum') ? $request->input('subscribe_day_maximum') : '';
- $officialAccount['appid'] = $appid;
- $officialAccount['distribution_channel_id'] = $distribution_channel_id;
- $officialAccount['appsecret'] = $appsecret;
- $officialAccount['alias'] = $alias;
- $officialAccount['name'] = $name;
- $officialAccount['nickname'] = $nickname;
- $officialAccount['head_img'] = $head_img;
- $officialAccount['qrcode_url'] = $qrcode_url;
- $officialAccount['principal_name'] = $principal_name;
- $officialAccount['service_type_info'] = $service_type_info;
- $officialAccount['func_info'] = $func_info;
- $officialAccount['authorizer_refresh_token'] = $authorizer_refresh_token;
- $officialAccount['is_auth'] = $is_auth;
- $officialAccount['official_account_type'] = $official_account_type;
- $officialAccount['is_enabled'] = $is_enabled;
- $officialAccount['verify_txt'] = $verify_txt;
- $officialAccount['subscribe_top_num'] = $subscribe_top_num;
- $officialAccount['subscribe_day_maximum'] = $subscribe_day_maximum;
- $resultStatus = OfficialAccountService::updateOfficialAccount($officialAccount);
- if ($resultStatus == 1) {
- return response()->success();
- }elseif ($resultStatus == 2) {
- return response()->error('OFFICIAL_ACCOUNT_NOT_FOUND');
- }elseif ($resultStatus == 0) {
- return response()->error('UPDATE_OFFICIAL_ACCOUNT_FAILED');
- }else{
- return response()->error('UPDATE_OFFICIAL_ACCOUNT_FAILED');
- }
-
-
- }
-
-
-
-
- function cancelAuthOfficialAccount(Request $request) {
- $appid = $request->has('appid') ? $request->input('appid') : '';
- if(empty($appid)) {
- return response()->error("PARAM_EMPTY");
- }
-
- $distribution_channel_id = $request->has('distribution_channel_id') ? $request->input('distribution_channel_id') : '';
- $officialAccount['appid'] = $appid;
- $officialAccount['distribution_channel_id'] = $distribution_channel_id;
- $resultStatus = OfficialAccountService::cancelAuthOfficialAccount($officialAccount);
-
- if ($resultStatus == 1) {
- return response()->success();
- }elseif ($resultStatus == 2) {
- return response()->error("CANCEL_OFFICIAL_ACCOUNT_FAILED");
- }elseif ($resultStatus == 0) {
- return response()->error("CANCEL_OFFICIAL_ACCOUNT_FAILED");
- }else{
- return response()->error("CANCEL_OFFICIAL_ACCOUNT_FAILED");
- }
- }
-
- function officialAccountAuthUrl(Request $request) {
-
- $distribution_channel_id = $request->has('distribution_channel_id') ? $request->input('distribution_channel_id') : '';
-
-
-
- $officialAccount['distribution_channel_id'] = $distribution_channel_id;
- $backurl = OfficialAccountService::officialAccountAuthUrl($officialAccount);
- return response()->success($backurl);
- }
-
- }
|