123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278 |
- <?php
- namespace app\service;
- use app\common\model\Mobile;
- use app\common\model\MobileOrder;
- use think\App;
- use think\helper\Str;
- use fast\Http;
- use GuzzleHttp\Client;
- class GantanhaoService{
- static $shareId = 310481;
- static $apiToken = 'emNApNcAmvGJu6H7HkWBD8OkmelQ4IgiLDLHqFDk8nHyr26Jah';
-
- public static function orderPurchase(MobileOrder $order){
-
- $url = 'https://notify.91haoka.cn/api/plan-market/order/purchase/v2';
- $mobile = $order['info']['mobile'];
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- $data = [
- 'multipart' => [
- [
- 'name' => 'sku',
- 'contents' => $mobile['product_no']
- ],
- [
- 'name' => 'source_id',
- 'contents' => $order['order_no']
- ],
- [
- 'name' => 'share_id',
- 'contents' => self::$shareId
- ],
- [
- 'name' => 'id_name',
- 'contents' => self::encrypt($order['name'])
- ],
- [
- 'name' => 'id_num',
- 'contents' => self::encrypt($order['id_no'])
- ],
- [
- 'name' => 'mobile',
- 'contents' => self::encrypt($order['phone'])
- ],
- [
- 'name' => 'name',
- 'contents' => self::encrypt($order['name'])
- ],
- [
- 'name' => 'address',
- 'contents' => self::encrypt($order['address'])
- ],
- [
- 'name' => 'pretty_number',
- 'contents' => $order['no']
- ],
- [
- 'name' => 'sign',
- 'contents' => self::orderSign($mobile['product_no'], $order['order_no'])
- ],
- ]
- ];
- if($mobile['card_status']){
- $i = 10;
- $open_idcard_face_img = parse_url($order['open_idcard_face_img']);
- $open_idcard_back_img = parse_url($order['open_idcard_back_img']);
- $open_face_img = parse_url($order['open_face_img']);
-
-
-
-
-
-
- $data['multipart'][$i]['name'] = 'pic[face]';
- $data['multipart'][$i]['contents'] = fopen(ROOT_PATH . 'public' .$open_idcard_face_img['path'], 'r');
- $data['multipart'][$i+1]['name'] = 'pic[back]';
- $data['multipart'][$i+1]['contents'] = fopen(ROOT_PATH . 'public' .$open_idcard_back_img['path'], 'r');
- $data['multipart'][$i+2]['name'] = 'pic[hand]';
- $data['multipart'][$i+2]['contents'] = fopen(ROOT_PATH . 'public' .$open_face_img['path'], 'r');
- }
- user_log('gantanhaoService', $data);
- try{
-
- $result = (new Client())->request('post', $url, $data);
- $rs = json_decode($result->getBody()->getContents(), true);
- user_log('gantanhaoService', '订单推送结果:'.json_encode($rs));
- if(is_null($rs) || $rs['msg']['code'] != 0) throw new \Exception($rs['msg']['info'] ?? '订单推送错误');
- $order['gantanhao_data'] = json_encode($rs['data']);
- if($rs['data']['status'] == 120){
- $order['status'] = 20;
- }
- $order->save();
- }
- catch(\Exception $e){
- user_log('gantanhaoService', '订单推送:'.$e->getMessage());
- throw new \Exception($e->getMessage());
- }
- }
-
- public static function orderPhotos($str_rand, $data){
- $url = 'http://notify.91haoka.cn/api/plan-market/order/photos';
- $open_idcard_face_img = parse_url($data['idcard_face_img']);
- $open_idcard_back_img = parse_url($data['idcard_back_img']);
- $open_face_img = parse_url($data['face_img']);
- $body = [
- 'multipart' => [
- [
- 'name' => 'str_rand',
- 'contents' => $str_rand
- ],
- [
- 'name' => 'pic[face]',
- 'contents' => fopen(ROOT_PATH . 'public' .$open_idcard_face_img['path'], 'r')
- ],
- [
- 'name' => 'pic[back]',
- 'contents' => fopen(ROOT_PATH . 'public' .$open_idcard_back_img['path'], 'r')
- ],
- [
- 'name' => 'pic[hand]',
- 'contents' => fopen(ROOT_PATH . 'public' .$open_face_img['path'], 'r')
- ],
- ]
- ];
- try{
-
- $result = (new Client())->request('post', $url, $body);
- $rs = json_decode($result->getBody()->getContents(), true);
- if(is_null($rs) || $rs['msg']['code'] != 0) throw new \Exception($rs['msg']['info'] ?? '身份证推送错误');
- return true;
- }
- catch(\Exception $e){
- user_log('gantanhaoService', '身份证推送:'.$e->getMessage());
- throw new \Exception($e->getMessage());
- }
-
- }
-
- public static function orderPhotoEncryption(MobileOrder $order){
- $url = 'http://notify.91haoka.cn/api/plan-market/order/photo/encryption';
-
- try{
- $sign = md5('order_id='.$order['order_no'].'&share_id='.self::$shareId .self::$apiToken);
-
- if(!$order['gantanhao_data']) throw new \Exception('订单未提单');
- $gantanhao = json_decode($order['gantanhao_data'], true);
- $data = [
- 'share_id' => self::$shareId,
- 'order_id' => $gantanhao['data']['id'],
- 'sign' => $sign
- ];
- $result = Http::post($url, http_build_query($data));
- $rs = json_decode($result, true);
- if(is_null($rs) || $rs['msg']['code'] != 0) throw new \Exception($rs['msg']['info'] ?? '获取上传照片密钥错误');
- return $rs['data']['str_rand'];
- }
- catch(\Exception $e){
- user_log('gantanhaoService', '获取上传照片密钥推送:'.$e->getMessage());
- throw new \Exception($e->getMessage());
- }
- }
-
- public static function orderSign($sku = '', $sourceId = ''){
- if(!$sku || !$sourceId) return false;
- $str = 'share_id='.self::$shareId .'&sku='.$sku.'&source_id='.$sourceId.self::$apiToken;
- return md5($str);
- }
-
- public static function checkSignNotify($data = []){
- if(!$data) return false;
- $str = 'outer_id='.$data['outer_id'].'&plan_mobile_produced='.$data['plan_mobile_produced'].'&status='.$data['status'].self::$apiToken;
- if(md5($str) != $data['sign']){
- return false;
- }
- return true;
- }
-
- public static function getSelectNum($product_sku){
- $url = 'http://notify.91haoka.cn/api/plan-market/upstream/num/select';
- try{
- $data = [
- 'product_sku' => $product_sku
- ];
- $result = Http::post($url, http_build_query($data));
- $rs = json_decode($result, true);
- if(is_null($rs) || $rs['msg']['code'] != 0) throw new \Exception($rs['msg']['info'] ?? '获取选号信息错误');
- return $rs['data'];
- }
- catch(\Exception $e){
- user_log('gantanhaoService', '获取选号信息:'.$e->getMessage());
- throw new \Exception($e->getMessage());
- }
- }
-
- public static function encrypt($data)
- {
- $aes_key = '121';
- return base64_encode(openssl_encrypt($data, 'aes-256-ecb', $aes_key, OPENSSL_RAW_DATA));
- }
-
- public static function jiemi($data){
- $aes_key = '121';
- $data = base64_decode($data);
- $data = openssl_decrypt($data, 'aes-256-ecb', $aes_key, OPENSSL_RAW_DATA);
- return $data;
- }
- }
|