OfficialAccountsController.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. <?php
  2. namespace App\Http\Controllers\Channel\OfficialAccount;
  3. use App\Http\Controllers\Channel\BaseController as ChannelBaseController;
  4. use App\Modules\OfficialAccount\Services\OfficialAccountService;
  5. use App\Http\Controllers\Channel\OfficialAccount\Transformers\OfficialAccountTransformer;
  6. use Illuminate\Http\Request;
  7. use GuzzleHttp\Client;
  8. use App\Libs\OSS;
  9. class OfficialAccountsController extends ChannelBaseController
  10. {
  11. /**
  12. * @apiDefine OfficialAccount 公众号
  13. */
  14. /**
  15. * @apiVersion 1.0.0
  16. * @api {GET} OfficialAccount/officialAccountAuthUrl 获取服务号授权URL
  17. * @apiGroup OfficialAccount
  18. * @apiName officialAccountAuthUrl
  19. * @apiSuccessExample {json} Success-Response:
  20. *
  21. * {
  22. * "code": 0,
  23. * "msg": "",
  24. * "data": []
  25. * }
  26. */
  27. function officialAccountAuthUrl(Request $request) {
  28. // $base_url = 'http://auth.aizhuishu.com/oauth_platform?';
  29. // $distribution_channel_id = $request->has('distribution_channel_id') ? $request->input('distribution_channel_id') : '';
  30. // if(empty($distribution_channel_id)) {
  31. // return response()->error("PARAM_EMPTY");
  32. // }
  33. $distribution_channel_id = $this->getChannelId();
  34. $officialAccount['distribution_channel_id'] = $distribution_channel_id;
  35. $url = OfficialAccountService::officialAccountAuthUrl($officialAccount);
  36. return response()->success(compact('url'));
  37. }
  38. /**
  39. * @apiVersion 1.0.0
  40. * @api {GET} OfficialAccount/allOfficialAccountBydistributionChannelId 根据分销渠道号获取服务号列表
  41. * @apiGroup OfficialAccount
  42. * @apiName allOfficialAccountBydistributionChannelId
  43. * @apiSuccess {Number} distribution_channel_id 分销渠道id.
  44. * @apiSuccess {String} name 公众号原始名称.
  45. * @apiSuccess {String} nickname 公众号名称.
  46. * @apiSuccess {String} alias 唯一ID.
  47. * @apiSuccess {String} qrcode_url 二维码地址.
  48. * @apiSuccess {String} principal_name 公司名称.
  49. * @apiSuccess {String} func_info 功能信息.
  50. * @apiSuccess {String} head_img 头像地址.
  51. * @apiSuccess {String} appid 微信appID.
  52. * @apiSuccess {String} appsecret 微信appsecret.
  53. * @apiSuccess {String} verify_txt 验证文件.
  54. * @apiSuccess {String} verify_type_info 授权方认证类型.
  55. * @apiSuccess {String} authorizer_refresh_token 授权的刷新token.
  56. * @apiSuccess {String} cancel_auth_time 取消授权时间.
  57. * @apiSuccess {String} official_account_type 第三方平台关注公众号.
  58. * @apiSuccess {Number} is_auth 是否授权.
  59. * @apiSuccess {String} service_type_info 服务号类型.
  60. * @apiSuccess {Number} subscribe_top_num 强制关注总额.
  61. * @apiSuccess {Number} subscribe_day_maximum 强制关注日限额.
  62. * @apiSuccess {Number} todayForceSubscribeUsers 今日关注总数.
  63. * @apiSuccess {Number} allForceSubscribeUsers 关注总数.
  64. * @apiSuccess {Number} is_enabled 是否可用.
  65. * @apiSuccess {Number} force_subscribe_type 强关类型 1默认强关2弱关注3链接强关
  66. * @apiSuccess {Number} resource_url .链接强关的地址
  67. * @apiSuccess {Number} force_subscribe_type_text .强关类型文本
  68. * @apiSuccessExample {json} Success-Response:
  69. *
  70. * {
  71. * "code": 0,
  72. * "msg": "",
  73. * "data": {
  74. * {
  75. * "name": "测试呵呵",
  76. * "nickname": "大哥",
  77. * "alias": "23534dsgdsvdx",
  78. * "head_img": "www.baidu.com",
  79. * "appid": "1211",
  80. * "appsecret": "dsfsdf3452352",
  81. * "verify_txt": null,
  82. * "is_auth": 1,
  83. * "service_type_info": "546dsfwr23r",
  84. * "subscribe_top_num": null,
  85. * "subscribe_day_maximum": null,
  86. * "distribution_channel_id": 1,
  87. * "qrcode_url": "fdhgfds435gsdfg43t",
  88. * "principal_name": "dfgh435saf2332",
  89. * "func_info": "ry3t342trwe",
  90. * "authorizer_refresh_token": "4534dfsgdsgsdgsdg",
  91. * "cancel_auth_time": null,
  92. * "official_account_type": "32dfaw234yewf",
  93. * "verify_type_info": null,
  94. * "is_enabled": 1,
  95. * "todayForceSubscribeUsers": 0,
  96. * "allForceSubscribeUsers": 0
  97. * }
  98. * }
  99. * }
  100. */
  101. function allOfficialAccountBydistributionChannelId(Request $request)
  102. {
  103. // $distribution_channel_id = $request->has('distribution_channel_id') ? $request->input('distribution_channel_id') : '';
  104. // if(empty($distribution_channel_id)) {
  105. // return response()->error("PARAM_EMPTY");
  106. // }
  107. $distribution_channel_id = $this->getChannelId();
  108. \Log::info('-------------------获取当前渠道下的所有服务号-----------------------------------');
  109. \Log::info($distribution_channel_id);
  110. $officialAccount['distribution_channel_id'] = $distribution_channel_id;
  111. $officialAccountService = OfficialAccountService::allOfficialAccountBydistributionChannelId($officialAccount);
  112. foreach ($officialAccountService as &$v){
  113. if(!$v->force_subscribe_type){
  114. $v->force_subscribe_type = ["1"];
  115. $v->force_subscribe_type_text = '强制关注';
  116. }else{
  117. $v->force_subscribe_type_text = str_replace([1,2,3],['强制关注','主动关注','强制链接关注'],$v->force_subscribe_type);
  118. $type_arr = explode(',',$v->force_subscribe_type);
  119. $v->force_subscribe_type = $type_arr;
  120. }
  121. }
  122. return response()->collection(new OfficialAccountTransformer(), $officialAccountService);
  123. }
  124. /**
  125. * @apiVersion 1.0.0
  126. * @api {GET} OfficialAccount/officialAccountById 通过Id获取要编辑的公众号
  127. * @apiGroup OfficialAccount
  128. * @apiName officialAccountById
  129. * @apiParam {String} id 微信公众号ID.
  130. * @apiSuccess {Number} distribution_channel_id 分销渠道id.
  131. * @apiSuccess {String} name 公众号原始名称.
  132. * @apiSuccess {String} nickname 公众号名称.
  133. * @apiSuccess {String} alias 唯一ID.
  134. * @apiSuccess {String} qrcode_url 二维码地址.
  135. * @apiSuccess {String} principal_name 公司名称.
  136. * @apiSuccess {String} func_info 功能信息.
  137. * @apiSuccess {String} head_img 头像地址.
  138. * @apiSuccess {String} appid 微信appID.
  139. * @apiSuccess {String} appsecret 微信appsecret.
  140. * @apiSuccess {String} verify_txt 验证文件.
  141. * @apiSuccess {String} verify_type_info 授权方认证类型.
  142. * @apiSuccess {String} authorizer_refresh_token 授权的刷新token.
  143. * @apiSuccess {String} cancel_auth_time 取消授权时间.
  144. * @apiSuccess {String} official_account_type 第三方平台关注公众号.
  145. * @apiSuccess {Number} is_auth 是否授权.
  146. * @apiSuccess {String} service_type_info 服务号类型.
  147. * @apiSuccess {Number} subscribe_top_num 强制关注总额.
  148. * @apiSuccess {Number} subscribe_day_maximum 强制关注日限额.
  149. * @apiSuccess {Number} is_enabled 是否可用.
  150. * @apiSuccessExample {json} Success-Response:
  151. *
  152. * {
  153. * "code": 0,
  154. * "msg": "",
  155. * "data": {
  156. * "name": "gh_0fdfe1e4f56c",
  157. * "nickname": "丸子书屋",
  158. * "alias": "wzsw166",
  159. * "head_img": "http://wx.qlogo.cn/mmopen/BDDBmFtJlKECdQ3ZeFKiaBMjU0ovndaib5tQQ1e7eXIIUCuKHGgnfwnDMdXecbpPmlstnnOicuHsiapvG71JbicBR52bapunZUvuu/0",
  160. * "appid": "wx6916de1267c67d50",
  161. * "appsecret": "wx6916de1267c67d501212",
  162. * "verify_txt": "",
  163. * "is_auth": "1",
  164. * "service_type_info": "2",
  165. * "subscribe_top_num": "10000",
  166. * "subscribe_day_maximum": "500",
  167. * "distribution_channel_id": 2147483647,
  168. * "qrcode_url": "fdhgfds435gsdfg43t",
  169. * "principal_name": "dfgh435saf2332",
  170. * "func_info": "ry3t342trwe",
  171. * "authorizer_refresh_token": "4534dfsgdsgsdgsdg",
  172. * "cancel_auth_time": null,
  173. * "official_account_type": "32dfaw234yewf",
  174. * "verify_type_info": null,
  175. * "is_enabled": 1
  176. * }
  177. * }
  178. */
  179. function officialAccountById(Request $request)
  180. {
  181. $id = $request->has('id') ? $request->input('id') : '';
  182. if(empty($id)) {
  183. return response()->error("PARAM_EMPTY");
  184. }
  185. $officialAccount['id'] = $id;
  186. $officialAccountService = OfficialAccountService::officialAccountById($officialAccount);
  187. return response()->item(new OfficialAccountTransformer(), $officialAccountService);
  188. }
  189. /**
  190. * @apiVersion 1.0.0
  191. * @api {POST} OfficialAccount/updateOfficialAccount 修改公众号信息
  192. * @apiGroup OfficialAccount
  193. * @apiName updateOfficialAccount
  194. * @apiParam {String} id 微信公众号ID.
  195. * @apiParam {String} subscribe_top_num 总阀值.
  196. * @apiParam {String} subscribe_day_maximum 日上线.
  197. * @apiSuccessExample {json} Success-Response:
  198. *
  199. * {
  200. * "code": 0,
  201. * "msg": "",
  202. * "data": []
  203. * }
  204. */
  205. function updateOfficialAccount(Request $request) {
  206. $id = $request->has('id') ? $request->input('id') : '';
  207. if(empty($id)) {
  208. return response()->error("PARAM_EMPTY");
  209. }
  210. //$appsecret = $request->has('appsecret') ? $request->input('appsecret') : '';
  211. $subscribe_top_num = $request->has('subscribe_top_num') ? $request->input('subscribe_top_num') : '';
  212. $subscribe_day_maximum = $request->has('subscribe_day_maximum') ? $request->input('subscribe_day_maximum') : '';
  213. $sort_no = $request->has('sort_no') ? $request->input('sort_no') : '0';
  214. $officialAccount['id'] = $id;
  215. //$officialAccount['appsecret'] = $appsecret;
  216. $officialAccount['subscribe_top_num'] = $subscribe_top_num;
  217. $officialAccount['subscribe_day_maximum'] = $subscribe_day_maximum;
  218. $officialAccount['sort_no'] = $sort_no;
  219. \Log::info($officialAccount);
  220. $resultStatus = OfficialAccountService::updateOfficialAccountTopNum($officialAccount);
  221. if ($resultStatus == 1) {
  222. return response()->success();
  223. }elseif ($resultStatus == 2) {
  224. return response()->error('OFFICIAL_ACCOUNT_NOT_FOUND');
  225. }elseif ($resultStatus == 0) {
  226. return response()->error('UPDATE_OFFICIAL_ACCOUNT_FAILED');
  227. }else{
  228. return response()->error('UPDATE_OFFICIAL_ACCOUNT_FAILED');
  229. }
  230. }
  231. function getShortUrl(Request $request) {
  232. \Log::info('getShortUrl');
  233. $url = $request->has('url') ? $request->input('url') : '';
  234. if(empty($url)) {
  235. return response()->error("PARAM_EMPTY");
  236. }
  237. $distribution_channel_id = $this->getChannelId();
  238. $result = OfficialAccountService::get_short_url($distribution_channel_id,$url);
  239. if ($result['code'] == 1 && !empty($result['url'])) {
  240. return response()->success($result['url']);
  241. }else{
  242. return response()->success($result['msg']);
  243. }
  244. }
  245. }