| Code Coverage
| Classes and Traits | Functions and Methods | Lines
Total | 0.00% covered (danger) | 0.00% | 0 / 1 | 0.00% covered (danger) | 0.00% | 0 / 3 | CRAP | 0.00% covered (danger) | 0.00% | 0 / 64
RejectedController | 0.00% covered (danger) | 0.00% | 0 / 1 | 0.00% covered (danger) | 0.00% | 0 / 3 | 110.00 | 0.00% covered (danger) | 0.00% | 0 / 64
sendRejected | 0.00% covered (danger) | 0.00% | 0 / 1 | 12.00 | 0.00% covered (danger) | 0.00% | 0 / 19
sendRejectedByApi | 0.00% covered (danger) | 0.00% | 0 / 1 | 12.00 | 0.00% covered (danger) | 0.00% | 0 / 16
packSendToRemote | 0.00% covered (danger) | 0.00% | 0 / 1 | 20.00 | 0.00% covered (danger) | 0.00% | 0 / 29

1 | <?php
2 |
3 |
4 | namespace App\Http\Controllers\api\jianshang;
5 |
6 |
7 | use App\Http\Controllers\Controller;
8 | use App\Rejected;
9 | use Carbon\Carbon;
10 | use Illuminate\Http\Request;
11 | use Illuminate\Support\Collection;
12 | use Zttp\Zttp;
13 |
14 | class RejectedController extends Controller
15 | {
16 | function sendRejected(Rejected $rejected){
17 | $amount = $rejected['amount'] ?? '';
18 | $created_at = $rejected['created_at'] ?? '';
19 | $fee_collected = $rejected['fee_collected'] ?? '';
20 | $goods_barcode = $rejected['barcode_goods'] ?? '';
21 | $goods_name = $rejected['name_goods'] ?? '';
22 | $logistic_name_return = $rejected->logisticName();
23 | $logistic_number = $rejected['logistic_number'] ?? '';
24 | $logistic_number_return = $rejected['logistic_number_return'] ?? '';
25 | $order_number = $rejected['order_number'] ?? '';
26 | $quality_label = $rejected->qualityLabelName();
27 | $sender_mobile = $rejected['mobile_sender'] ?? '';
28 | $sender_name = $rejected['sender'] ?? '';
29 | $json = $this->packSendToRemote($amount,$created_at,$fee_collected,$goods_barcode,
30 | $goods_name,$logistic_name_return,$logistic_number,$logistic_number_return,$order_number,
31 | $quality_label,$sender_mobile,$sender_name);
32 | if(!$json)return false;
33 | if(!$json['success']){
34 | $this->log(__METHOD__,'error',"返回错误：".json_encode($json));
35 | return false;
36 | }else{
37 | $this->log(__METHOD__,'JianshangResponse',json_encode($json));
38 | }
39 | return $json;
40 | }
41 | function sendRejectedByApi(Request $request){
42 | $amount = $request->input('amount') ?? '';
43 | $created_at = $request->input('created_at') ?? '';
44 | $fee_collected = $request->input('fee_collected') ?? '';
45 | $goods_barcode = $request->input('goods_barcode') ?? '';
46 | $goods_name = $request->input('goods_name') ?? '';
47 | $logistic_name_return = $request->input('logistic_name_return') ?? '';
48 | $logistic_number = $request->input('logistic_number') ?? '';
49 | $logistic_number_return = $request->input('logistic_number_return') ?? '';
50 | $order_number = $request->input('order_number') ?? '';
51 | $quality_label = $request->input('quality_label') ?? '';
52 | $sender_mobile = $request->input('sender_mobile') ?? '';
53 | $sender_name = $request->input('sender_name') ?? '';
54 | $json = $this->packSendToRemote($amount,$created_at,$fee_collected,$goods_barcode,
55 | $goods_name,$logistic_name_return,$logistic_number,$logistic_number_return,$order_number,
56 | $quality_label,$sender_mobile,$sender_name);
57 | if(!$json)return ['success'=>'false','fail_info'=>'没有JSON回复'];
58 | if(!$json['success']){return $this->apiError(__METHOD__,"返回错误：".json_encode($json));}
59 | return $json;
60 | }
61 | private function packSendToRemote($amount,$created_at,$fee_collected,$goods_barcode,
62 | $goods_name,$logistic_name_return,$logistic_number,$logistic_number_return,$order_number,
63 | $quality_label,$sender_mobile,$sender_name){
64 | if(env('api_faking'))return false;
65 | $data="{\"amount\":\"$amount\", \"created_at\":\"$created_at\", \"fee_collected\":\"$fee_collected\",
66 | \"goods_barcode\":\"$goods_barcode\", \"goods_name\":\"$goods_name\", \"logistic_name_return\":\"$logistic_name_return\",
67 | \"logistic_number\":\"$logistic_number\", \"logistic_number_return\":\"$logistic_number_return\",
68 | \"order_number\":\"$order_number\", \"quality_label\":\"$quality_label\", \"sender_mobile\":\"$sender_mobile\", \"sender_name\":\"$sender_name\"}";
69 | $sortParamsAndMd5=function(Array $params,$timestamp,$nonce,$signKey){
70 | $params=new Collection($params);
71 | $params=$params->sortKeys();
72 | $str='';
73 | $params->each(function($param,$key)use(&$str){
74 | $val=trim($param);
75 | if($val){
76 | $str .= $key.$val;
77 | }
78 | });
79 | return strtolower(md5($str.$timestamp.$nonce.$signKey));
80 | };
81 | $timestamp=intval(microtime(true)*1000);
82 | $nonce=md5(microtime(true));
83 | $sign=$sortParamsAndMd5(json_decode($data,true),$timestamp,$nonce,config('api.sign_key_rejected_send_jianshang'));
84 | $url=config('api.url_rejected_send_jianshang');
85 | $response=Zttp::withHeaders([
86 | 'sign'=>$sign,
87 | 'nonce'=>$nonce,
88 | 'timestamp'=>$timestamp,
89 | 'Content-Type'=>'application/json'
90 | ])->post($url,json_decode($data,true));
91 | $this->log(__METHOD__,'json',$data);
92 | if(!$response){
93 | $this->log(__METHOD__,'error','回复异常：'.$response->body());
94 | return false;
95 | }
96 | return $response->json();
97 | }
98 |
99 | }