OfficialAccountsController.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  1. <?php
  2. namespace App\Http\Controllers\Wechat\OfficialAccount;
  3. use App\Http\Controllers\Channel\BaseController as ChannelBaseController;
  4. use App\Modules\OfficialAccount\Services\OfficialAccountService;
  5. use App\Modules\OfficialAccount\Models\OfficialAccount;
  6. use App\Modules\OfficialAccount\Models\ForceSubscribeUsers;
  7. use App\Http\Controllers\Wechat\OfficialAccount\Transformers\OfficialAccountTransformer;
  8. use Illuminate\Http\Request;
  9. use GuzzleHttp\Client;
  10. use App\Libs\OSS;
  11. class OfficialAccountsController extends ChannelBaseController
  12. {
  13. /**
  14. * @apiDefine OfficialAccount 公众号
  15. */
  16. /**
  17. * @apiVersion 1.0.0
  18. * @api {GET} OfficialAccount/officialAccountByAppid 通过appid获取公众号
  19. * @apiGroup OfficialAccount
  20. * @apiName officialAccountByAppid
  21. * @apiParam {String} appid 微信appID.
  22. * @apiSuccess {Number} distribution_channel_id 分销渠道id.
  23. * @apiSuccess {String} name 公众号原始名称.
  24. * @apiSuccess {String} nickname 公众号名称.
  25. * @apiSuccess {String} alias 唯一ID.
  26. * @apiSuccess {String} qrcode_url 二维码地址.
  27. * @apiSuccess {String} principal_name 公司名称.
  28. * @apiSuccess {String} func_info 功能信息.
  29. * @apiSuccess {String} head_img 头像地址.
  30. * @apiSuccess {String} appid 微信appID.
  31. * @apiSuccess {String} appsecret 微信appsecret.
  32. * @apiSuccess {String} verify_txt 验证文件.
  33. * @apiSuccess {String} verify_type_info 授权方认证类型.
  34. * @apiSuccess {String} authorizer_refresh_token 授权的刷新token.
  35. * @apiSuccess {String} cancel_auth_time 取消授权时间.
  36. * @apiSuccess {String} official_account_type 第三方平台关注公众号.
  37. * @apiSuccess {Number} is_auth 是否授权.
  38. * @apiSuccess {String} service_type_info 服务号类型.
  39. * @apiSuccess {Number} subscribe_top_num 强制关注总额.
  40. * @apiSuccess {Number} subscribe_day_maximum 强制关注日限额.
  41. * @apiSuccess {Number} is_enabled 是否可用.
  42. * @apiSuccessExample {json} Success-Response:
  43. *
  44. * {
  45. * "code": 0,
  46. * "msg": "",
  47. * "data": {
  48. * "name": "gh_0fdfe1e4f56c",
  49. * "nickname": "丸子书屋",
  50. * "alias": "wzsw166",
  51. * "head_img": "http://wx.qlogo.cn/mmopen/BDDBmFtJlKECdQ3ZeFKiaBMjU0ovndaib5tQQ1e7eXIIUCuKHGgnfwnDMdXecbpPmlstnnOicuHsiapvG71JbicBR52bapunZUvuu/0",
  52. * "appid": "wx6916de1267c67d50",
  53. * "appsecret": "wx6916de1267c67d501212",
  54. * "verify_txt": "",
  55. * "is_auth": "1",
  56. * "service_type_info": "2",
  57. * "subscribe_top_num": "10000",
  58. * "subscribe_day_maximum": "500",
  59. * "distribution_channel_id": 2147483647,
  60. * "qrcode_url": "fdhgfds435gsdfg43t",
  61. * "principal_name": "dfgh435saf2332",
  62. * "func_info": "ry3t342trwe",
  63. * "authorizer_refresh_token": "4534dfsgdsgsdgsdg",
  64. * "cancel_auth_time": null,
  65. * "official_account_type": "32dfaw234yewf",
  66. * "verify_type_info": null,
  67. * "is_enabled": 1
  68. * }
  69. * }
  70. */
  71. function officialAccountByAppid(Request $request)
  72. {
  73. $appid = $request->has('appid') ? $request->input('appid') : '';
  74. \Log::info('==========================进入officialAccountByAppid方法'.$appid);
  75. if(empty($appid)) {
  76. return response()->error("PARAM_EMPTY");
  77. }
  78. $officialAccount['appid'] = $appid;
  79. $officialAccountService = OfficialAccountService::officialAccountByAppid($officialAccount);
  80. return response()->item(new OfficialAccountTransformer(), $officialAccountService);
  81. }
  82. /**
  83. * @apiVersion 1.0.0
  84. * @api {GET} OfficialAccount/canUseOfficialAccountByChannelId 获取可分配的公众号
  85. * @apiGroup OfficialAccount
  86. * @apiName canUseOfficialAccountByChannelId
  87. * @apiParam {String} distribution_channel_id 分销渠道id.
  88. * @apiSuccess {Number} distribution_channel_id 分销渠道id.
  89. * @apiSuccess {String} name 公众号原始名称.
  90. * @apiSuccess {String} nickname 公众号名称.
  91. * @apiSuccess {String} alias 唯一ID.
  92. * @apiSuccess {String} qrcode_url 二维码地址.
  93. * @apiSuccess {String} principal_name 公司名称.
  94. * @apiSuccess {String} func_info 功能信息.
  95. * @apiSuccess {String} head_img 头像地址.
  96. * @apiSuccess {String} appid 微信appID.
  97. * @apiSuccess {String} appsecret 微信appsecret.
  98. * @apiSuccess {String} verify_txt 验证文件.
  99. * @apiSuccess {String} verify_type_info 授权方认证类型.
  100. * @apiSuccess {String} authorizer_refresh_token 授权的刷新token.
  101. * @apiSuccess {String} cancel_auth_time 取消授权时间.
  102. * @apiSuccess {String} official_account_type 第三方平台关注公众号.
  103. * @apiSuccess {Number} is_auth 是否授权.
  104. * @apiSuccess {String} service_type_info 服务号类型.
  105. * @apiSuccess {Number} subscribe_top_num 强制关注总额.
  106. * @apiSuccess {Number} subscribe_day_maximum 强制关注日限额.
  107. * @apiSuccess {Number} is_enabled 是否可用.
  108. * @apiSuccessExample {json} Success-Response:
  109. *
  110. * {
  111. * "code": 0,
  112. * "msg": "",
  113. * "data": {
  114. * "name": "gh_0fdfe1e4f56c",
  115. * "nickname": "丸子书屋",
  116. * "alias": "wzsw166",
  117. * "head_img": "http://wx.qlogo.cn/mmopen/BDDBmFtJlKECdQ3ZeFKiaBMjU0ovndaib5tQQ1e7eXIIUCuKHGgnfwnDMdXecbpPmlstnnOicuHsiapvG71JbicBR52bapunZUvuu/0",
  118. * "appid": "wx6916de1267c67d50",
  119. * "appsecret": "wx6916de1267c67d501212",
  120. * "verify_txt": "",
  121. * "is_auth": "1",
  122. * "service_type_info": "2",
  123. * "subscribe_top_num": "10000",
  124. * "subscribe_day_maximum": "500",
  125. * "distribution_channel_id": 2147483647,
  126. * "qrcode_url": "fdhgfds435gsdfg43t",
  127. * "principal_name": "dfgh435saf2332",
  128. * "func_info": "ry3t342trwe",
  129. * "authorizer_refresh_token": "4534dfsgdsgsdgsdg",
  130. * "cancel_auth_time": null,
  131. * "official_account_type": "32dfaw234yewf",
  132. * "verify_type_info": null,
  133. * "is_enabled": 1
  134. * }
  135. * }
  136. */
  137. function canUseOfficialAccountByChannelId(Request $request)
  138. {
  139. $distribution_channel_id = $request->has('distribution_channel_id') ? $request->input('distribution_channel_id') : '';
  140. if(empty($distribution_channel_id)) {
  141. return response()->error("PARAM_EMPTY");
  142. }
  143. $officialAccount['distribution_channel_id'] = $distribution_channel_id;
  144. $officialAccountService = OfficialAccountService::canUseOfficialAccountByChannelId($officialAccount);
  145. return response()->item(new OfficialAccountTransformer(), $officialAccountService);
  146. }
  147. /**
  148. * @apiVersion 1.0.0
  149. * @api {GET} OfficialAccount/officialAuthAccountBydistributionChannelId 根据分销渠道号获取所有授权的公众号
  150. * @apiGroup OfficialAccount
  151. * @apiName officialAuthAccountBydistributionChannelId
  152. * @apiParam {String} distribution_channel_id 分销渠道Id.
  153. * @apiSuccess {Number} distribution_channel_id 分销渠道id.
  154. * @apiSuccess {String} name 公众号原始名称.
  155. * @apiSuccess {String} nickname 公众号名称.
  156. * @apiSuccess {String} alias 唯一ID.
  157. * @apiSuccess {String} qrcode_url 二维码地址.
  158. * @apiSuccess {String} principal_name 公司名称.
  159. * @apiSuccess {String} func_info 功能信息.
  160. * @apiSuccess {String} head_img 头像地址.
  161. * @apiSuccess {String} appid 微信appID.
  162. * @apiSuccess {String} appsecret 微信appsecret.
  163. * @apiSuccess {String} verify_txt 验证文件.
  164. * @apiSuccess {String} verify_type_info 授权方认证类型.
  165. * @apiSuccess {String} authorizer_refresh_token 授权的刷新token.
  166. * @apiSuccess {String} cancel_auth_time 取消授权时间.
  167. * @apiSuccess {String} official_account_type 第三方平台关注公众号.
  168. * @apiSuccess {Number} is_auth 是否授权.
  169. * @apiSuccess {String} service_type_info 服务号类型.
  170. * @apiSuccess {Number} subscribe_top_num 强制关注总额.
  171. * @apiSuccess {Number} subscribe_day_maximum 强制关注日限额.
  172. * @apiSuccess {Number} is_enabled 是否可用.
  173. * @apiSuccessExample {json} Success-Response:
  174. *
  175. * {
  176. * "code": 0,
  177. * "msg": "",
  178. * "data": {
  179. * "name": "gh_0fdfe1e4f56c",
  180. * "nickname": "丸子书屋",
  181. * "alias": "wzsw166",
  182. * "head_img": "http://wx.qlogo.cn/mmopen/BDDBmFtJlKECdQ3ZeFKiaBMjU0ovndaib5tQQ1e7eXIIUCuKHGgnfwnDMdXecbpPmlstnnOicuHsiapvG71JbicBR52bapunZUvuu/0",
  183. * "appid": "wx6916de1267c67d50",
  184. * "appsecret": "wx6916de1267c67d501212",
  185. * "verify_txt": "",
  186. * "is_auth": "1",
  187. * "service_type_info": "2",
  188. * "subscribe_top_num": "10000",
  189. * "subscribe_day_maximum": "500",
  190. * "distribution_channel_id": 2147483647,
  191. * "qrcode_url": "fdhgfds435gsdfg43t",
  192. * "principal_name": "dfgh435saf2332",
  193. * "func_info": "ry3t342trwe",
  194. * "authorizer_refresh_token": "4534dfsgdsgsdgsdg",
  195. * "cancel_auth_time": null,
  196. * "official_account_type": "32dfaw234yewf",
  197. * "verify_type_info": null,
  198. * "is_enabled": 1
  199. * }
  200. * }
  201. */
  202. function officialAuthAccountBydistributionChannelId(Request $request)
  203. {
  204. $distribution_channel_id = $request->has('distribution_channel_id') ? $request->input('distribution_channel_id') : '';
  205. if(empty($distribution_channel_id)) {
  206. return response()->error("PARAM_EMPTY");
  207. }
  208. $officialAccount['distribution_channel_id'] = $distribution_channel_id;
  209. $officialAccountService = OfficialAccountService::officialAuthAccountBydistributionChannelId($officialAccount);
  210. return response()->collection(new OfficialAccountTransformer(), $officialAccountService);
  211. }
  212. /**
  213. * @apiVersion 1.0.0
  214. * @api {GET} OfficialAccount/allOfficialAccountBydistributionChannelId 根据分销渠道号获取服务号列表
  215. * @apiGroup OfficialAccount
  216. * @apiName allOfficialAccountBydistributionChannelId
  217. * @apiParam {String} distribution_channel_id 分销渠道Id.
  218. * @apiSuccess {Number} distribution_channel_id 分销渠道id.
  219. * @apiSuccess {String} name 公众号原始名称.
  220. * @apiSuccess {String} nickname 公众号名称.
  221. * @apiSuccess {String} alias 唯一ID.
  222. * @apiSuccess {String} qrcode_url 二维码地址.
  223. * @apiSuccess {String} principal_name 公司名称.
  224. * @apiSuccess {String} func_info 功能信息.
  225. * @apiSuccess {String} head_img 头像地址.
  226. * @apiSuccess {String} appid 微信appID.
  227. * @apiSuccess {String} appsecret 微信appsecret.
  228. * @apiSuccess {String} verify_txt 验证文件.
  229. * @apiSuccess {String} verify_type_info 授权方认证类型.
  230. * @apiSuccess {String} authorizer_refresh_token 授权的刷新token.
  231. * @apiSuccess {String} cancel_auth_time 取消授权时间.
  232. * @apiSuccess {String} official_account_type 第三方平台关注公众号.
  233. * @apiSuccess {Number} is_auth 是否授权.
  234. * @apiSuccess {String} service_type_info 服务号类型.
  235. * @apiSuccess {Number} subscribe_top_num 强制关注总额.
  236. * @apiSuccess {Number} subscribe_day_maximum 强制关注日限额.
  237. * @apiSuccess {Number} todayForceSubscribeUsers 今日关注总数.
  238. * @apiSuccess {Number} allForceSubscribeUsers 关注总数.
  239. * @apiSuccess {Number} is_enabled 是否可用.
  240. * @apiSuccessExample {json} Success-Response:
  241. *
  242. * {
  243. * "code": 0,
  244. * "msg": "",
  245. * "data": {
  246. * {
  247. * "name": "测试呵呵",
  248. * "nickname": "大哥",
  249. * "alias": "23534dsgdsvdx",
  250. * "head_img": "www.baidu.com",
  251. * "appid": "1211",
  252. * "appsecret": "dsfsdf3452352",
  253. * "verify_txt": null,
  254. * "is_auth": 1,
  255. * "service_type_info": "546dsfwr23r",
  256. * "subscribe_top_num": null,
  257. * "subscribe_day_maximum": null,
  258. * "distribution_channel_id": 1,
  259. * "qrcode_url": "fdhgfds435gsdfg43t",
  260. * "principal_name": "dfgh435saf2332",
  261. * "func_info": "ry3t342trwe",
  262. * "authorizer_refresh_token": "4534dfsgdsgsdgsdg",
  263. * "cancel_auth_time": null,
  264. * "official_account_type": "32dfaw234yewf",
  265. * "verify_type_info": null,
  266. * "is_enabled": 1,
  267. * "todayForceSubscribeUsers": 0,
  268. * "allForceSubscribeUsers": 0
  269. * }
  270. * }
  271. * }
  272. */
  273. function allOfficialAccountBydistributionChannelId(Request $request)
  274. {
  275. $distribution_channel_id = $request->has('distribution_channel_id') ? $request->input('distribution_channel_id') : '';
  276. if(empty($distribution_channel_id)) {
  277. return response()->error("PARAM_EMPTY");
  278. }
  279. $officialAccount['distribution_channel_id'] = $distribution_channel_id;
  280. $officialAccountService = OfficialAccountService::allOfficialAccountBydistributionChannelId($officialAccount);
  281. return response()->collection(new OfficialAccountTransformer(), $officialAccountService);
  282. }
  283. /**
  284. * @apiVersion 1.0.0
  285. * @api {POST} OfficialAccount/authOfficialAccount 授权公众号信息
  286. * @apiGroup OfficialAccount
  287. * @apiName authOfficialAccount
  288. * @apiParam {String} appid 微信appID.
  289. * @apiParam {String} name 公众号原始名称.
  290. * @apiParam {String} nickname 公众号名称.
  291. * @apiParam {String} alias 唯一ID.
  292. * @apiParam {String} head_img 头像地址.
  293. * @apiParam {String} appid 微信appID.
  294. * @apiParam {String} appsecret 微信appsecret.
  295. * @apiParam {String} is_auth 是否授权.
  296. * @apiParam {String} service_type_info 服务号类型.
  297. * @apiParam {Number} distribution_channel_id 分销渠道id.
  298. * @apiParam {String} qrcode_url 二维码地址.
  299. * @apiParam {String} principal_name 公司名称.
  300. * @apiParam {String} func_info 功能信息.
  301. * @apiParam {String} authorizer_refresh_token 授权的刷新token.
  302. * @apiParam {String} official_account_type 第三方平台关注公众号.
  303. * @apiSuccessExample {json} Success-Response:
  304. *
  305. * {
  306. * "code": 0,
  307. * "msg": "",
  308. * "data": []
  309. * }
  310. */
  311. function authOfficialAccount(Request $request) {
  312. $appid = $request->has('appid') ? $request->input('appid') : '';
  313. // $distribution_channel_id = $this->getChannelId();
  314. $distribution_channel_id = $request->has('distribution_channel_id') ? $request->input('distribution_channel_id') : '';
  315. $appsecret = $request->has('appsecret') ? $request->input('appsecret') : '';
  316. $alias = $request->has('alias') ? $request->input('alias') : '';
  317. $name = $request->has('name') ? $request->input('name') : '';
  318. $nickname = $request->has('nickname') ? $request->input('nickname') : '';
  319. $head_img = $request->has('head_img') ? $request->input('head_img') : '';
  320. $qrcode_url = $request->has('qrcode_url') ? $request->input('qrcode_url') : '';
  321. $principal_name = $request->has('principal_name') ? $request->input('principal_name') : '';
  322. $service_type_info = $request->has('service_type_info') ? $request->input('service_type_info') : '';
  323. $func_info = $request->has('func_info') ? $request->input('func_info') : '';
  324. $authorizer_refresh_token = $request->has('authorizer_refresh_token') ? $request->input('authorizer_refresh_token') : '';
  325. $is_auth = $request->has('is_auth') ? $request->input('is_auth') : '1';
  326. $official_account_type = $request->has('official_account_type') ? $request->input('official_account_type') : '';
  327. $is_enabled = 1;
  328. $verify_txt = $request->has('verify_txt') ? $request->input('verify_txt') : '';
  329. $officialAccount['appid'] = $appid;
  330. $officialAccount['distribution_channel_id'] = $distribution_channel_id;
  331. $officialAccount['appsecret'] = $appsecret;
  332. $officialAccount['alias'] = $alias;
  333. $officialAccount['name'] = $name;
  334. $officialAccount['nickname'] = $nickname;
  335. $officialAccount['head_img'] = $head_img;
  336. $officialAccount['qrcode_url'] = $qrcode_url;
  337. $officialAccount['principal_name'] = $principal_name;
  338. $officialAccount['service_type_info'] = $service_type_info;
  339. $officialAccount['func_info'] = $func_info;
  340. $officialAccount['authorizer_refresh_token'] = $authorizer_refresh_token;
  341. $officialAccount['is_auth'] = $is_auth;
  342. $officialAccount['official_account_type'] = $official_account_type;
  343. $officialAccount['is_enabled'] = $is_enabled;
  344. $officialAccount['verify_txt'] = $verify_txt;
  345. \Log::info($appid.':auth:create:params');
  346. \Log::info($officialAccount);
  347. $resultStatus = OfficialAccountService::authOfficialAccount($officialAccount);
  348. if ($resultStatus == 1) {
  349. return response()->success();
  350. }elseif ($resultStatus == 2) {
  351. return response()->error('OFFICIAL_ACCOUNT_IS_EXIST');
  352. }elseif ($resultStatus == 0) {
  353. return response()->error('OFFICIAL_ACCOUNT_FAILED');
  354. }else{
  355. return response()->error('OFFICIAL_ACCOUNT_FAILED');
  356. }
  357. }
  358. /**
  359. * @apiVersion 1.0.0
  360. * @api {POST} OfficialAccount/updateOfficialAccount 修改公众号信息
  361. * @apiGroup OfficialAccount
  362. * @apiName updateOfficialAccount
  363. * @apiParam {String} appid 微信appID.
  364. * @apiParam {String} appsecret 微信appsecret.
  365. * @apiParam {String} distribution_channel_id 分销渠道id.
  366. * @apiParam {String} subscribe_top_num 总阀值.
  367. * @apiParam {String} subscribe_day_maximum 日上线.
  368. * @apiSuccessExample {json} Success-Response:
  369. *
  370. * {
  371. * "code": 0,
  372. * "msg": "",
  373. * "data": []
  374. * }
  375. */
  376. function updateOfficialAccount(Request $request) {
  377. $appid = $request->has('appid') ? $request->input('appid') : '';
  378. $distribution_channel_id = $request->has('distribution_channel_id') ? $request->input('distribution_channel_id') : '';
  379. // $distribution_channel_id = $this->getChannelId();
  380. $appsecret = $request->has('appsecret') ? $request->input('appsecret') : '';
  381. $alias = $request->has('alias') ? $request->input('alias') : '';
  382. $name = $request->has('name') ? $request->input('name') : '';
  383. $nickname = $request->has('nickname') ? $request->input('nickname') : '';
  384. $head_img = $request->has('head_img') ? $request->input('head_img') : '';
  385. $qrcode_url = $request->has('qrcode_url') ? $request->input('qrcode_url') : '';
  386. $principal_name = $request->has('principal_name') ? $request->input('principal_name') : '';
  387. $service_type_info = $request->has('service_type_info') ? $request->input('service_type_info') : '';
  388. $func_info = $request->has('func_info') ? $request->input('func_info') : '';
  389. $authorizer_refresh_token = $request->has('authorizer_refresh_token') ? $request->input('authorizer_refresh_token') : '';
  390. $is_auth = $request->has('is_auth') ? $request->input('is_auth') : '1';
  391. $official_account_type = $request->has('official_account_type') ? $request->input('official_account_type') : '';
  392. $is_enabled = 1;
  393. $verify_txt = $request->has('verify_txt') ? $request->input('verify_txt') : '';
  394. $subscribe_top_num = $request->has('subscribe_top_num') ? $request->input('subscribe_top_num') : '';
  395. $subscribe_day_maximum = $request->has('subscribe_day_maximum') ? $request->input('subscribe_day_maximum') : '';
  396. $officialAccount['appid'] = $appid;
  397. $officialAccount['distribution_channel_id'] = $distribution_channel_id;
  398. $officialAccount['appsecret'] = $appsecret;
  399. $officialAccount['alias'] = $alias;
  400. $officialAccount['name'] = $name;
  401. $officialAccount['nickname'] = $nickname;
  402. $officialAccount['head_img'] = $head_img;
  403. $officialAccount['qrcode_url'] = $qrcode_url;
  404. $officialAccount['principal_name'] = $principal_name;
  405. $officialAccount['service_type_info'] = $service_type_info;
  406. $officialAccount['func_info'] = $func_info;
  407. $officialAccount['authorizer_refresh_token'] = $authorizer_refresh_token;
  408. $officialAccount['is_auth'] = $is_auth;
  409. $officialAccount['official_account_type'] = $official_account_type;
  410. $officialAccount['is_enabled'] = $is_enabled;
  411. $officialAccount['verify_txt'] = $verify_txt;
  412. $officialAccount['subscribe_top_num'] = $subscribe_top_num;
  413. $officialAccount['subscribe_day_maximum'] = $subscribe_day_maximum;
  414. $resultStatus = OfficialAccountService::updateOfficialAccount($officialAccount);
  415. if ($resultStatus == 1) {
  416. return response()->success();
  417. }elseif ($resultStatus == 2) {
  418. return response()->error('OFFICIAL_ACCOUNT_NOT_FOUND');
  419. }elseif ($resultStatus == 0) {
  420. return response()->error('UPDATE_OFFICIAL_ACCOUNT_FAILED');
  421. }else{
  422. return response()->error('UPDATE_OFFICIAL_ACCOUNT_FAILED');
  423. }
  424. }
  425. // public function getUserClient(){
  426. // return new Client(['base_uri' => env('PUBLIC_API_BASE_URI')]);
  427. // }
  428. /**
  429. * @apiVersion 1.0.0
  430. * @api {GET} OfficialAccount/cancelAuthOfficialAccount 取消公众号授权
  431. * @apiGroup OfficialAccount
  432. * @apiName cancelAuthOfficialAccount
  433. * @apiParam {String} appid 微信appID.
  434. * @apiSuccessExample {json} Success-Response:
  435. *
  436. * {
  437. * "code": 0,
  438. * "msg": "",
  439. * "data": []
  440. * }
  441. */
  442. function cancelAuthOfficialAccount(Request $request) {
  443. $appid = $request->has('appid') ? $request->input('appid') : '';
  444. if(empty($appid)) {
  445. return response()->error("PARAM_EMPTY");
  446. }
  447. // $distribution_channel_id = $this->getChannelId();
  448. $distribution_channel_id = $request->has('distribution_channel_id') ? $request->input('distribution_channel_id') : '';
  449. $officialAccount['appid'] = $appid;
  450. $officialAccount['distribution_channel_id'] = $distribution_channel_id;
  451. $resultStatus = OfficialAccountService::cancelAuthOfficialAccount($officialAccount);
  452. if ($resultStatus == 1) {
  453. return response()->success();
  454. }elseif ($resultStatus == 2) {
  455. return response()->error("CANCEL_OFFICIAL_ACCOUNT_FAILED");
  456. }elseif ($resultStatus == 0) {
  457. return response()->error("CANCEL_OFFICIAL_ACCOUNT_FAILED");
  458. }else{
  459. return response()->error("CANCEL_OFFICIAL_ACCOUNT_FAILED");
  460. }
  461. }
  462. /**
  463. * @apiVersion 1.0.0
  464. * @api {GET} OfficialAccount/officialAccountAuthUrl 获取服务号授权URL
  465. * @apiGroup OfficialAccount
  466. * @apiName officialAccountAuthUrl
  467. * @apiParam {String} distribution_channel_id 分销渠道ID.
  468. * @apiSuccessExample {json} Success-Response:
  469. *
  470. * {
  471. * "code": 0,
  472. * "msg": "",
  473. * "data": []
  474. * }
  475. */
  476. function officialAccountAuthUrl(Request $request) {
  477. // $distribution_channel_id = $this->getChannelId();
  478. $distribution_channel_id = $request->has('distribution_channel_id') ? $request->input('distribution_channel_id') : '';
  479. // if(empty($distribution_channel_id)) {
  480. // return response()->error("PARAM_EMPTY");
  481. // }
  482. $officialAccount['distribution_channel_id'] = $distribution_channel_id;
  483. $backurl = OfficialAccountService::officialAccountAuthUrl($officialAccount);
  484. return response()->success($backurl);
  485. }
  486. }