123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329 |
- <?php
- namespace App\Service;
- use App\Log;
- use App\Support\EmailQueue;
- class HuaShengService
- {
- # 猎豆优选 - web
- const API_KEY_3 = '588588162';
- const API_SECURITY_3 = '1e4bae5013576d29d6e235e75458529a';
- const GET_MERCHANTS = 'https://vip.rlcps.cn/api/getMerchants';
- const GET_ORDER_LIST = 'https://vip.rlcps.cn/api/orderList';
- const GET_SPREAD_LIST_OF_WEB = 'https://vip.rlcps.cn/api/get-spread-list';
- # 杭州猎豆 - 小程序
- const MERCHANT_ID_MINI_PROGRAM_3 = 51;
- const API_KEY_FOR_MINI_PROGRAM_3 = 'B4v7otDkDsU2jBi3';
- const API_SECURITY_FOR_MINI_PROGRAM_3 = '43419734985e8e031279ac71d6761d24';
- # 星橙优品 - 小程序
- const MERCHANT_ID_MINI_PROGRAM_51 = 186;
- const API_KEY_FOR_MINI_PROGRAM_51 = 'JOXzXW0m3NOAOKFx';
- const API_SECURITY_FOR_MINI_PROGRAM_51 = 'e01ea1a21f85b9629816012216df7779';
- const GET_APPLET_LIST = 'https://api.dpxkjw.com/api/get-applet-list-by-merchant';
- const GET_OPTIMIZER_LIST = 'https://api.dpxkjw.com/api/get-optimizer-list-by-applet';
- const GET_CHANNEL_LIST = 'https://api.dpxkjw.com/api/get-channel-list-by-optimizer';
- const GET_ORDER_LIST_OF_MINI_PROGRAM = 'https://api.dpxkjw.com/api/get-order-list-by-channel';
- /*
- * 生成签名
- * */
- public static function getSign($data, $type=1)
- {
- if($type == 1) {
- $security = self::API_SECURITY_3;
- } else if(2 == $type) {
- $security = self::API_SECURITY_FOR_MINI_PROGRAM_3;
- } else if(3 == $type) {
- $security = self::API_SECURITY_FOR_MINI_PROGRAM_51;
- }
- ksort($data, SORT_REGULAR);
- $splicedString = '';
- foreach ($data as $paramKey => $paramValue) {
- $splicedString .= trim($paramValue);
- }
- if($splicedString){
- $splicedString = strtoupper(md5($splicedString . $security));
- }
- return $splicedString;
- }
- /**
- * 获取vip账户下的所有商户信息
- * */
- public static function getMerchants($params, $retry=0)
- {
- try {
- $response = HttpService::httpPost(self::GET_MERCHANTS, $params);
- if($response === false && $retry <5) { // 发起重试
- $retry++;
- return HuaShengService::getMerchants($params, $retry);
- }
- $responseData = json_decode($response, true);
- if($responseData['code'] != 0) {
- EmailQueue::rPush('花生获取VIP账户下的所有商户信息返回错误', json_encode($responseData), ['xiaohua.hou@kuxuan-inc.com'], '花生获取VIP账户下的所有商户信息返回错误');
- Log::logError('花生获取VIP账户下的所有商户信息返回错误', ['response' => $response], 'HuaShengApi');
- return [];
- }
- return $responseData['data'];
- } catch (\Exception $e) {
- EmailQueue::rPush('获取VIP账户下的所有商户信息发生异常', $e->getTraceAsString(), ['xiaohua.hou@kuxuan-inc.com'], '获取VIP账户下的所有商户信息发生异常');
- Log::logError('获取VIP账户下的所有商户信息发生异常', [
- 'line' => $e->getLine(),
- 'msg' => $e->getMessage()
- ], 'HuaShengApi-Exception');
- }
- return [];
- }
- /**
- * 获取花生订单
- * */
- public static function getOrderList($params, $retry=0)
- {
- try {
- $response = HttpService::httpPost(self::GET_ORDER_LIST, $params);
- if($response === false && $retry <5) { // 发起重试
- $retry++;
- return HuaShengService::getOrderList($params, $retry);
- }
- $responseData = json_decode($response, true);
- if(empty($responseData) || !isset($responseData['code'])) {
- return [[], 0];
- }
- if($responseData['code'] != 0) {
- EmailQueue::rPush('花生获取VIP账户下的订单信息返回错误', json_encode($responseData), ['xiaohua.hou@kuxuan-inc.com'], '花生获取VIP账户下的订单信息返回错误');
- Log::logError('花生获取VIP账户下的订单信息返回错误', ['response' => $response], 'HuaShengApi');
- return [[], 0];
- }
- return [$responseData['data'], $responseData['count']];
- } catch (\Exception $e) {
- EmailQueue::rPush('获取VIP账户下的订单信息发生异常', $e->getTraceAsString(), ['xiaohua.hou@kuxuan-inc.com'], '获取VIP账户下的订单信息发生异常');
- Log::logError('获取VIP账户下的订单信息发生异常', [
- 'line' => $e->getLine(),
- 'msg' => $e->getMessage()
- ], 'HuaShengApi-Exception');
- }
- return [[], 0];
- }
- /**
- * 获取花生小程序列表
- * */
- public static function getApplet($params, $retry=0)
- {
- try {
- $response = HttpService::httpPost(self::GET_APPLET_LIST, $params);
- if($response === false && $retry <5) { // 发起重试
- $retry++;
- return HuaShengService::getApplet($params, $retry);
- }
- $responseData = json_decode($response, true);
- if($responseData['code'] != 0) {
- EmailQueue::rPush('花生获取小程序列表信息返回错误', json_encode($responseData), ['xiaohua.hou@kuxuan-inc.com'], '花生获取小程序列表信息返回错误');
- Log::logError('花生获取小程序列表信息返回错误', ['response' => $response], 'HuaShengApi');
- return [];
- }
- return $responseData['data'];
- } catch (\Exception $e) {
- EmailQueue::rPush('花生获取小程序列表信息发生异常', $e->getTraceAsString(), ['xiaohua.hou@kuxuan-inc.com'], '花生获取小程序列表信息发生异常');
- Log::logError('花生获取小程序列表信息发生异常', [
- 'line' => $e->getLine(),
- 'msg' => $e->getMessage()
- ], 'HuaShengApi-Exception');
- }
- return [];
- }
- /**
- * 获取小程序下优化师列表
- * */
- public static function getOptimizer($params, $retry=0)
- {
- try {
- $response = HttpService::httpPost(self::GET_OPTIMIZER_LIST, $params);
- if($response === false && $retry <5) { // 发起重试
- $retry++;
- return HuaShengService::getOptimizer($params, $retry);
- }
- $responseData = json_decode($response, true);
- if($responseData['code'] != 0) {
- EmailQueue::rPush('花生获取小程序下优化师列表返回错误', json_encode($responseData), ['xiaohua.hou@kuxuan-inc.com'], '花生小程序下优化师列表返回错误');
- Log::logError('花生小程序下优化师列表返回错误', ['response' => $response], 'HuaShengApi');
- return [];
- }
- return $responseData['data'];
- } catch (\Exception $e) {
- EmailQueue::rPush('花生获取小程序下优化师列表发生异常', $e->getTraceAsString(), ['xiaohua.hou@kuxuan-inc.com'], '花生获取小程序下优化师列表发生异常');
- Log::logError('花生获取小程序下优化师列表发生异常', [
- 'line' => $e->getLine(),
- 'msg' => $e->getMessage()
- ], 'HuaShengApi-Exception');
- }
- return [];
- }
- /**
- * 获取优化师下渠道/公众号列表
- * */
- public static function getChannelList($params, $retry=0)
- {
- try {
- $response = HttpService::httpPost(self::GET_CHANNEL_LIST, $params);
- if($response === false && $retry <5) { // 发起重试
- $retry++;
- return HuaShengService::getChannelList($params, $retry);
- }
- $responseData = json_decode($response, true);
- if(!isset($responseData['code']) || $responseData['code'] != 0) {
- // EmailQueue::rPush('花生获取优化师下渠道/公众号列表返回错误', json_encode([$responseData, $params]), ['xiaohua.hou@kuxuan-inc.com'], '花生优化师下渠道/公众号列表返回错误');
- Log::logError('花生优化师下渠道/公众号列表返回错误', ['response' => $response, 'params' => $params], 'HuaShengApi');
- return [];
- }
- return $responseData['data'];
- } catch (\Exception $e) {
- EmailQueue::rPush('花生优化师下渠道/公众号列表发生异常', $e->getTraceAsString(), ['xiaohua.hou@kuxuan-inc.com'], '花生优化师下渠道/公众号列表发生异常');
- Log::logError('花生优化师下渠道/公众号列表发生异常', [
- 'line' => $e->getLine(),
- 'msg' => $e->getMessage()
- ], 'HuaShengApi-Exception');
- }
- return [];
- }
- /**
- * 获取公众号/渠道日订单列表
- * */
- public static function getOrderListOfMiniProgram($params, $retry=0)
- {
- try {
- $response = HttpService::httpPost(self::GET_ORDER_LIST_OF_MINI_PROGRAM, $params);
- if($response === false && $retry <5) { // 发起重试
- $retry++;
- return HuaShengService::getOrderListOfMiniProgram($params, $retry);
- }
- $responseData = json_decode($response, true);
- if(empty($responseData)) {
- Log::logError('花生获取小程序订单信息返回空数据', ['response' => $response], 'HuaShengApi');
- return [[], 0];
- }
- if($responseData['code'] != 0) {
- // EmailQueue::rPush('花生获取小程序订单信息返回错误', json_encode($responseData), ['xiaohua.hou@kuxuan-inc.com'], '花生获取小程序订单信息返回错误');
- Log::logError('花生获取小程序订单信息返回错误', ['response' => $response], 'HuaShengApi');
- return [[], 0];
- }
- return [$responseData['data']['data'], $responseData['data']['count']];
- } catch (\Exception $e) {
- EmailQueue::rPush('获取花生小程序订单信息发生异常', $e->getTraceAsString(), ['xiaohua.hou@kuxuan-inc.com'], '获取花生小程序订单信息发生异常');
- Log::logError('获取花生小程序订单信息发生异常', [
- 'line' => $e->getLine(),
- 'msg' => $e->getMessage()
- ], 'HuaShengApi-Exception');
- }
- return [[], 0];
- }
- public static function getSpreadList($params, $retry = 0)
- {
- try {
- $response = HttpService::httpPost(self::GET_SPREAD_LIST_OF_WEB, $params);
- if($response === false && $retry <5) { // 发起重试
- $retry++;
- return HuaShengService::getSpreadList($params, $retry);
- }
- $responseData = json_decode($response, true);
- if($responseData['code'] != 0) {
- EmailQueue::rPush('花生获取H5推广列表返回错误', json_encode($responseData), ['song.shen@kuxuan-inc.com'], '花生获取H5推广列表返回错误');
- Log::logError('花生获取H5推广列表返回错误', ['response' => $response], 'HuaShengApi');
- return [[], 0];
- }
- return [$responseData['data'], $responseData['count']];
- } catch (\Exception $e) {
- EmailQueue::rPush('花生获取H5推广列表发生异常', $e->getTraceAsString(), ['xiaohua.hou@kuxuan-inc.com'], '花生获取H5推广列表发生异常');
- Log::logError('花生获取H5推广列表发生异常', [
- 'line' => $e->getLine(),
- 'msg' => $e->getMessage()
- ], 'HuaShengApi-Exception');
- }
- return [[], 0];
- }
- public static function getOrderPayType($way) {
- $arr = [
- 1 => 7,// 微信支付
- 2 => 5,// 支付宝支付
- 10 => 15,// 抖音支付
- 30 => 1,// 虚拟支付
- 40 => 16,// 半屏支付
- ];
- return $arr[$way] ?? 0;
- }
- public static function getOrderOs($order) {
- if(!isset($order['mobile_os'])) {
- $order['os'] = 0;
- $order['user_agent'] = null;
- EmailQueue::rPush('第三方平台设备类型异常', json_encode([
- 'platform' => '花生小程序', 'msg' => '设备类型字段不存在', 'order_data' => $order
- ], 256), ['song.shen@kuxuan-inc.com'], '猎羽');
- return $order;
- }
- switch($order['mobile_os']){
- case 'Android':
- $order['os'] = 1;
- break;
- case 'iOS':
- $order['os'] = 2;
- break;
- default:
- $order['os'] = 0;
- EmailQueue::rPush('第三方平台设备类型异常', json_encode([
- 'platform' => '花生小程序', 'msg' => '设备类型字段值不在预期内', 'order_data' => $order
- ], 256), ['song.shen@kuxuan-inc.com'], '猎羽');
- break;
- }
- $order['user_agent'] = $order['mobile_os'];
- return $order;
- }
- }
|