OfficialWechatUserController.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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\WechatTemplates;
  6. use Illuminate\Http\Request;
  7. use GuzzleHttp\Client;
  8. use App\Libs\OSS;
  9. class OfficialWechatUserController extends ChannelBaseController
  10. {
  11. /**
  12. * @apiDefine OfficialAccount 公众号
  13. */
  14. /**
  15. * @apiVersion 1.0.0
  16. * @api {GET} OfficialAccount/saveOfficialWechatUser 新增微信公众号用户
  17. * @apiGroup OfficialAccount
  18. * @apiName saveOfficialWechatUser
  19. * @apiParam {String} openid 微信openid..
  20. * @apiParam {String} unionid 微信unionid.
  21. * @apiParam {String} distribution_channel_id 分销渠道ID.
  22. * @apiParam {String} [province] 省份.
  23. * @apiParam {String} [city] 城市.
  24. * @apiParam {String} [country] 国家.
  25. * @apiParam {String} [headimgurl] 头像地址.
  26. * @apiParam {String} [send_order_id] 派单ID.
  27. * @apiParam {String} [sex] 性别.允许值: 0, 1.
  28. * @apiSuccessExample {json} Success-Response:
  29. *
  30. * {
  31. * "code": 0,
  32. * "msg": "",
  33. * "data": {
  34. *
  35. * }
  36. * }
  37. */
  38. function saveOfficialWechatUser(Request $request)
  39. {
  40. $openid = $request->has('openid') ? $request->input('openid') : '';
  41. if(empty($openid)) {
  42. return response()->error("PARAM_EMPTY");
  43. }
  44. $unionid = $request->has('unionid') ? $request->input('unionid') : '';
  45. if(empty($unionid)) {
  46. return response()->error("PARAM_EMPTY");
  47. }
  48. $distribution_channel_id = $request->has('distribution_channel_id') ? $request->input('distribution_channel_id') : '';
  49. if(empty($distribution_channel_id)) {
  50. return response()->error("PARAM_EMPTY");
  51. }
  52. $province = $request->has('province') ? $request->input('province') : '';
  53. $city = $request->has('city') ? $request->input('city') : '';
  54. $country = $request->has('country') ? $request->input('country') : '';
  55. $headimgurl = $request->has('headimgurl') ? $request->input('headimgurl') : '';
  56. $send_order_id = $request->has('send_order_id') ? $request->input('send_order_id') : '';
  57. $sex = $request->has('sex') ? $request->input('sex') : '';
  58. $user['openid'] = $openid;
  59. $user['unionid'] = $unionid;
  60. $user['distribution_channel_id'] = $distribution_channel_id;
  61. $user['province'] = $province;
  62. $user['city'] = $city;
  63. $user['country'] = $country;
  64. $user['headimgurl'] = $headimgurl;
  65. $user['send_order_id'] = $send_order_id;
  66. $user['sex'] = $sex;
  67. $resultStatus = OfficialAccountService::saveOfficialWechatUser($user);
  68. if ($resultStatus == 1) {
  69. return response()->success();
  70. }elseif ($resultStatus == 2) {
  71. return response()->error('WECHAT_USER_REQUEST_ERROR');
  72. }elseif ($resultStatus == 0) {
  73. return response()->error('WECHAT_USER_REQUEST_ERROR');
  74. }else{
  75. return response()->error('WECHAT_USER_REQUEST_ERROR');
  76. }
  77. }
  78. /**
  79. * @apiVersion 1.0.0
  80. * @api {GET} OfficialAccount/getOfficialWechatUser 获取公众号用户
  81. * @apiGroup OfficialAccount
  82. * @apiName getOfficialWechatUser
  83. * @apiParam {Number} id ID.
  84. * @apiSuccess {Number} id ID.
  85. * @apiSuccess {String} openid 微信openid.
  86. * @apiSuccess {String} unionid 微信unionid.
  87. * @apiSuccess {String} distribution_channel_id 分销渠道ID.
  88. * @apiSuccess {String} [province] 省份.
  89. * @apiSuccess {String} [city] 城市.
  90. * @apiSuccess {String} [country] 国家.
  91. * @apiSuccess {String} [headimgurl] 头像地址.
  92. * @apiSuccess {String} [send_order_id] 派单ID.
  93. * @apiSuccess {String} [sex] 性别.允许值: 0, 1.
  94. * @apiSuccessExample {json} Success-Response:
  95. *
  96. * {
  97. * "code": 0,
  98. * "msg": "",
  99. * "data": {
  100. * "id": 1,
  101. * "openid": "121212",
  102. * "unionid": "232323",
  103. * "head_img": "",
  104. * "distribution_channel_id": 2,
  105. * "register_ip": "",
  106. * "send_order_id": 0,
  107. * "balance": 0,
  108. * "country": "",
  109. * "city": "",
  110. * "sex": 1,
  111. * "register_time": "2017-11-22 11:04:33"
  112. * }
  113. * }
  114. */
  115. function getOfficialWechatUser(Request $request)
  116. {
  117. $id = $request->has('id') ? $request->input('id') : '';
  118. if(empty($id)) {
  119. return response()->error("PARAM_EMPTY");
  120. }
  121. $officialWechatUser['id'] = $id;
  122. $user = OfficialAccountService::getOfficialWechatUser($officialWechatUser);
  123. return response()->success($user);
  124. }
  125. }