企微短剧业务系统

HuaShengService.php 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. <?php
  2. namespace App\Service;
  3. use App\Log;
  4. use App\Support\EmailQueue;
  5. class HuaShengService
  6. {
  7. # 猎豆优选 - web
  8. const API_KEY_3 = '588588162';
  9. const API_SECURITY_3 = '1e4bae5013576d29d6e235e75458529a';
  10. const GET_MERCHANTS = 'https://vip.rlcps.cn/api/getMerchants';
  11. const GET_ORDER_LIST = 'https://vip.rlcps.cn/api/orderList';
  12. const GET_SPREAD_LIST_OF_WEB = 'https://vip.rlcps.cn/api/get-spread-list';
  13. # 杭州猎豆 - 小程序
  14. const MERCHANT_ID_MINI_PROGRAM_3 = 51;
  15. const API_KEY_FOR_MINI_PROGRAM_3 = 'B4v7otDkDsU2jBi3';
  16. const API_SECURITY_FOR_MINI_PROGRAM_3 = '43419734985e8e031279ac71d6761d24';
  17. # 星橙优品 - 小程序
  18. const MERCHANT_ID_MINI_PROGRAM_51 = 186;
  19. const API_KEY_FOR_MINI_PROGRAM_51 = 'JOXzXW0m3NOAOKFx';
  20. const API_SECURITY_FOR_MINI_PROGRAM_51 = 'e01ea1a21f85b9629816012216df7779';
  21. const GET_APPLET_LIST = 'https://api.dpxkjw.com/api/get-applet-list-by-merchant';
  22. const GET_OPTIMIZER_LIST = 'https://api.dpxkjw.com/api/get-optimizer-list-by-applet';
  23. const GET_CHANNEL_LIST = 'https://api.dpxkjw.com/api/get-channel-list-by-optimizer';
  24. const GET_ORDER_LIST_OF_MINI_PROGRAM = 'https://api.dpxkjw.com/api/get-order-list-by-channel';
  25. /*
  26. * 生成签名
  27. * */
  28. public static function getSign($data, $type=1)
  29. {
  30. if($type == 1) {
  31. $security = self::API_SECURITY_3;
  32. } else if(2 == $type) {
  33. $security = self::API_SECURITY_FOR_MINI_PROGRAM_3;
  34. } else if(3 == $type) {
  35. $security = self::API_SECURITY_FOR_MINI_PROGRAM_51;
  36. }
  37. ksort($data, SORT_REGULAR);
  38. $splicedString = '';
  39. foreach ($data as $paramKey => $paramValue) {
  40. $splicedString .= trim($paramValue);
  41. }
  42. if($splicedString){
  43. $splicedString = strtoupper(md5($splicedString . $security));
  44. }
  45. return $splicedString;
  46. }
  47. /**
  48. * 获取vip账户下的所有商户信息
  49. * */
  50. public static function getMerchants($params, $retry=0)
  51. {
  52. try {
  53. $response = HttpService::httpPost(self::GET_MERCHANTS, $params);
  54. if($response === false && $retry <5) { // 发起重试
  55. $retry++;
  56. return HuaShengService::getMerchants($params, $retry);
  57. }
  58. $responseData = json_decode($response, true);
  59. if($responseData['code'] != 0) {
  60. EmailQueue::rPush('花生获取VIP账户下的所有商户信息返回错误', json_encode($responseData), ['xiaohua.hou@kuxuan-inc.com'], '花生获取VIP账户下的所有商户信息返回错误');
  61. Log::logError('花生获取VIP账户下的所有商户信息返回错误', ['response' => $response], 'HuaShengApi');
  62. return [];
  63. }
  64. return $responseData['data'];
  65. } catch (\Exception $e) {
  66. EmailQueue::rPush('获取VIP账户下的所有商户信息发生异常', $e->getTraceAsString(), ['xiaohua.hou@kuxuan-inc.com'], '获取VIP账户下的所有商户信息发生异常');
  67. Log::logError('获取VIP账户下的所有商户信息发生异常', [
  68. 'line' => $e->getLine(),
  69. 'msg' => $e->getMessage()
  70. ], 'HuaShengApi-Exception');
  71. }
  72. return [];
  73. }
  74. /**
  75. * 获取花生订单
  76. * */
  77. public static function getOrderList($params, $retry=0)
  78. {
  79. try {
  80. $response = HttpService::httpPost(self::GET_ORDER_LIST, $params);
  81. if($response === false && $retry <5) { // 发起重试
  82. $retry++;
  83. return HuaShengService::getOrderList($params, $retry);
  84. }
  85. $responseData = json_decode($response, true);
  86. if(empty($responseData) || !isset($responseData['code'])) {
  87. return [[], 0];
  88. }
  89. if($responseData['code'] != 0) {
  90. EmailQueue::rPush('花生获取VIP账户下的订单信息返回错误', json_encode($responseData), ['xiaohua.hou@kuxuan-inc.com'], '花生获取VIP账户下的订单信息返回错误');
  91. Log::logError('花生获取VIP账户下的订单信息返回错误', ['response' => $response], 'HuaShengApi');
  92. return [[], 0];
  93. }
  94. return [$responseData['data'], $responseData['count']];
  95. } catch (\Exception $e) {
  96. EmailQueue::rPush('获取VIP账户下的订单信息发生异常', $e->getTraceAsString(), ['xiaohua.hou@kuxuan-inc.com'], '获取VIP账户下的订单信息发生异常');
  97. Log::logError('获取VIP账户下的订单信息发生异常', [
  98. 'line' => $e->getLine(),
  99. 'msg' => $e->getMessage()
  100. ], 'HuaShengApi-Exception');
  101. }
  102. return [[], 0];
  103. }
  104. /**
  105. * 获取花生小程序列表
  106. * */
  107. public static function getApplet($params, $retry=0)
  108. {
  109. try {
  110. $response = HttpService::httpPost(self::GET_APPLET_LIST, $params);
  111. if($response === false && $retry <5) { // 发起重试
  112. $retry++;
  113. return HuaShengService::getApplet($params, $retry);
  114. }
  115. $responseData = json_decode($response, true);
  116. if($responseData['code'] != 0) {
  117. EmailQueue::rPush('花生获取小程序列表信息返回错误', json_encode($responseData), ['xiaohua.hou@kuxuan-inc.com'], '花生获取小程序列表信息返回错误');
  118. Log::logError('花生获取小程序列表信息返回错误', ['response' => $response], 'HuaShengApi');
  119. return [];
  120. }
  121. return $responseData['data'];
  122. } catch (\Exception $e) {
  123. EmailQueue::rPush('花生获取小程序列表信息发生异常', $e->getTraceAsString(), ['xiaohua.hou@kuxuan-inc.com'], '花生获取小程序列表信息发生异常');
  124. Log::logError('花生获取小程序列表信息发生异常', [
  125. 'line' => $e->getLine(),
  126. 'msg' => $e->getMessage()
  127. ], 'HuaShengApi-Exception');
  128. }
  129. return [];
  130. }
  131. /**
  132. * 获取小程序下优化师列表
  133. * */
  134. public static function getOptimizer($params, $retry=0)
  135. {
  136. try {
  137. $response = HttpService::httpPost(self::GET_OPTIMIZER_LIST, $params);
  138. if($response === false && $retry <5) { // 发起重试
  139. $retry++;
  140. return HuaShengService::getOptimizer($params, $retry);
  141. }
  142. $responseData = json_decode($response, true);
  143. if($responseData['code'] != 0) {
  144. EmailQueue::rPush('花生获取小程序下优化师列表返回错误', json_encode($responseData), ['xiaohua.hou@kuxuan-inc.com'], '花生小程序下优化师列表返回错误');
  145. Log::logError('花生小程序下优化师列表返回错误', ['response' => $response], 'HuaShengApi');
  146. return [];
  147. }
  148. return $responseData['data'];
  149. } catch (\Exception $e) {
  150. EmailQueue::rPush('花生获取小程序下优化师列表发生异常', $e->getTraceAsString(), ['xiaohua.hou@kuxuan-inc.com'], '花生获取小程序下优化师列表发生异常');
  151. Log::logError('花生获取小程序下优化师列表发生异常', [
  152. 'line' => $e->getLine(),
  153. 'msg' => $e->getMessage()
  154. ], 'HuaShengApi-Exception');
  155. }
  156. return [];
  157. }
  158. /**
  159. * 获取优化师下渠道/公众号列表
  160. * */
  161. public static function getChannelList($params, $retry=0)
  162. {
  163. try {
  164. $response = HttpService::httpPost(self::GET_CHANNEL_LIST, $params);
  165. if($response === false && $retry <5) { // 发起重试
  166. $retry++;
  167. return HuaShengService::getChannelList($params, $retry);
  168. }
  169. $responseData = json_decode($response, true);
  170. if(!isset($responseData['code']) || $responseData['code'] != 0) {
  171. // EmailQueue::rPush('花生获取优化师下渠道/公众号列表返回错误', json_encode([$responseData, $params]), ['xiaohua.hou@kuxuan-inc.com'], '花生优化师下渠道/公众号列表返回错误');
  172. Log::logError('花生优化师下渠道/公众号列表返回错误', ['response' => $response, 'params' => $params], 'HuaShengApi');
  173. return [];
  174. }
  175. return $responseData['data'];
  176. } catch (\Exception $e) {
  177. EmailQueue::rPush('花生优化师下渠道/公众号列表发生异常', $e->getTraceAsString(), ['xiaohua.hou@kuxuan-inc.com'], '花生优化师下渠道/公众号列表发生异常');
  178. Log::logError('花生优化师下渠道/公众号列表发生异常', [
  179. 'line' => $e->getLine(),
  180. 'msg' => $e->getMessage()
  181. ], 'HuaShengApi-Exception');
  182. }
  183. return [];
  184. }
  185. /**
  186. * 获取公众号/渠道日订单列表
  187. * */
  188. public static function getOrderListOfMiniProgram($params, $retry=0)
  189. {
  190. try {
  191. $response = HttpService::httpPost(self::GET_ORDER_LIST_OF_MINI_PROGRAM, $params);
  192. if($response === false && $retry <5) { // 发起重试
  193. $retry++;
  194. return HuaShengService::getOrderListOfMiniProgram($params, $retry);
  195. }
  196. $responseData = json_decode($response, true);
  197. if(empty($responseData)) {
  198. Log::logError('花生获取小程序订单信息返回空数据', ['response' => $response], 'HuaShengApi');
  199. return [[], 0];
  200. }
  201. if($responseData['code'] != 0) {
  202. // EmailQueue::rPush('花生获取小程序订单信息返回错误', json_encode($responseData), ['xiaohua.hou@kuxuan-inc.com'], '花生获取小程序订单信息返回错误');
  203. Log::logError('花生获取小程序订单信息返回错误', ['response' => $response], 'HuaShengApi');
  204. return [[], 0];
  205. }
  206. return [$responseData['data']['data'], $responseData['data']['count']];
  207. } catch (\Exception $e) {
  208. EmailQueue::rPush('获取花生小程序订单信息发生异常', $e->getTraceAsString(), ['xiaohua.hou@kuxuan-inc.com'], '获取花生小程序订单信息发生异常');
  209. Log::logError('获取花生小程序订单信息发生异常', [
  210. 'line' => $e->getLine(),
  211. 'msg' => $e->getMessage()
  212. ], 'HuaShengApi-Exception');
  213. }
  214. return [[], 0];
  215. }
  216. public static function getSpreadList($params, $retry = 0)
  217. {
  218. try {
  219. $response = HttpService::httpPost(self::GET_SPREAD_LIST_OF_WEB, $params);
  220. if($response === false && $retry <5) { // 发起重试
  221. $retry++;
  222. return HuaShengService::getSpreadList($params, $retry);
  223. }
  224. $responseData = json_decode($response, true);
  225. if($responseData['code'] != 0) {
  226. EmailQueue::rPush('花生获取H5推广列表返回错误', json_encode($responseData), ['song.shen@kuxuan-inc.com'], '花生获取H5推广列表返回错误');
  227. Log::logError('花生获取H5推广列表返回错误', ['response' => $response], 'HuaShengApi');
  228. return [[], 0];
  229. }
  230. return [$responseData['data'], $responseData['count']];
  231. } catch (\Exception $e) {
  232. EmailQueue::rPush('花生获取H5推广列表发生异常', $e->getTraceAsString(), ['xiaohua.hou@kuxuan-inc.com'], '花生获取H5推广列表发生异常');
  233. Log::logError('花生获取H5推广列表发生异常', [
  234. 'line' => $e->getLine(),
  235. 'msg' => $e->getMessage()
  236. ], 'HuaShengApi-Exception');
  237. }
  238. return [[], 0];
  239. }
  240. public static function getOrderPayType($way) {
  241. $arr = [
  242. 1 => 7,// 微信支付
  243. 2 => 5,// 支付宝支付
  244. 10 => 15,// 抖音支付
  245. 30 => 1,// 虚拟支付
  246. 40 => 16,// 半屏支付
  247. ];
  248. return $arr[$way] ?? 0;
  249. }
  250. public static function getOrderOs($order) {
  251. if(!isset($order['mobile_os'])) {
  252. $order['os'] = 0;
  253. $order['user_agent'] = null;
  254. EmailQueue::rPush('第三方平台设备类型异常', json_encode([
  255. 'platform' => '花生小程序', 'msg' => '设备类型字段不存在', 'order_data' => $order
  256. ], 256), ['song.shen@kuxuan-inc.com'], '猎羽');
  257. return $order;
  258. }
  259. switch($order['mobile_os']){
  260. case 'Android':
  261. $order['os'] = 1;
  262. break;
  263. case 'iOS':
  264. $order['os'] = 2;
  265. break;
  266. default:
  267. $order['os'] = 0;
  268. EmailQueue::rPush('第三方平台设备类型异常', json_encode([
  269. 'platform' => '花生小程序', 'msg' => '设备类型字段值不在预期内', 'order_data' => $order
  270. ], 256), ['song.shen@kuxuan-inc.com'], '猎羽');
  271. break;
  272. }
  273. $order['user_agent'] = $order['mobile_os'];
  274. return $order;
  275. }
  276. }