123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- <?php
- namespace App\Http\Controllers\Api;
- use App\Model\BoxDetail;
- use App\Service\Box\BoxHookService;
- use App\Service\DwyService;
- use App\Service\LabelDealService;
- use App\Service\MeasureService;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\Log;
- class TestController extends BaseController
- {
- private $ivBytes = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F";
- public function deviceCallback(Request $request){
- $sign = $this->makeSign(['appid'=>'ehiV145x0sq2pIdR'],'zcJOeS7Ty1Zk5sEYQ36ia9UbDxWgGRlm');
- // var_dump($sign);
- var_dump($sign);die;
- }
- function makeSign($params,$appkey,$sign_type=1){
- ksort($params);
- unset($params['sign']);
- $str = '';
- foreach($params as $key=>$val){
- if(is_array($val)){
- continue;
- }
- if($sign_type == 1 || !$sign_type){
- if(strlen($val) > 0){
- $str.= trim($val);
- }
- }else{
- if(strlen($val) > 0){
- $str.= trim($key).'='.trim($val);
- }
- }
- }
- $hash_hmac = hash_hmac('sha256', $str, $appkey, true);
- return urlencode(base64_encode($hash_hmac));
- }
- public function boxInsert(){
- $data = [
- 'out_order_no' => 'test123',
- 'ext_1' => '1',
- 'ext_2' => '2',
- 'ext_3' => '3',
- 'ext_4' => '4',
- 'ext_5' => '5',
- 'detail' => [
- [
- 'top_id' => '1',
- 'code' => '001',
- 'title' => '产品名称',
- 'ext_1' => '1',
- 'ext_2' => '2',
- 'ext_3' => '3',
- 'ext_4' => '4',
- 'ext_5' => '5',
- ],[
- 'top_id' => '2',
- 'code' => '002',
- 'title' => '产品名称1',
- 'ext_1' => '11',
- 'ext_2' => '22',
- 'ext_3' => '33',
- 'ext_4' => '44',
- 'ext_5' => '55',
- ],
- ],
- ];
- $service = BoxHookService::getInstance();
- list($status,$msg) = $service->boxInsert($data);
- var_dump($status);
- var_dump($msg);
- }
- public function aa(){
- //处理数据
- $data = '{"param":{"key":"DV00001","lead_bind":{"device_code":"DV00001","material_list":[{"product_code":"BC020202000999","fake_qty":"5","product_code_show":"信息部测试1800香杉木","order_item_id":"599057977894375424","order_item_id_show":"SO202407110062","material_code":"40010101000999","material_code_show":"E0批零免漆(测试白标)","process_title":"挪威森林","process_title_two":null,"color":"测试花色01","color_two":null,"mat_material_a":{"mat_category_code_show":"免漆板1800香杉木","mat_category_code":"BC020202","cpdj_show":"尊贵型","cpdj":"cpdj01","grade_show":"E0","grade":"01"},"brand_qr_code_list":["K45SDTL4BGIT93MVEPM1","EK60TLDMP1G26WD2G38R","CS0OMSFOS8UB480KP7UY","ME9D9RFU69B79YLM6V9J","N8CPA3WOWGBPFH6M1VUV"],"order_no_list":"SO202407110062"},{"product_code":"BC020202000999","fake_qty":"5","product_code_show":"信息部测试1800香杉木","order_item_id":"599057977894375424","order_item_id_show":"SO202407110062","material_code":"40010501000999","material_code_show":"银盾抗菌圆标(测试白标)","process_title":"挪威森林","process_title_two":null,"color":"测试花色01","color_two":null,"mat_material_a":{"mat_category_code_show":"免漆板1800香杉木","mat_category_code":"BC020202","cpdj_show":"尊贵型","cpdj":"cpdj01","grade_show":"E0","grade":"01"},"brand_qr_code_list":["6A51SIUC74AJ8E2JECGP","8VP60YJ5D7C3DX9R93XY","UJ4R8XMJ49AKXQOSW376","8VP6VYJ0CFWRQ49SD3X8","1R6B8DOCUVN67DA2G6A2"],"order_no_list":"SO202407110062"}]},"lead_out":{"brand_out_stock_list":[{"in_out_type_code":"CK00004","in_out_type_code_show":"商标仓正常领标出库","send_box_code":"CK00011","send_box_code_show":"商标八号仓","device_code":"DV00001","get_brand_source_dk":"SALE_ORDER","abnormal_flag":false,"abnormal_date":"2024-08-26T16:53:29.109Z","brand_out_stock_dtl":[{"item_no":10,"brand_qr_code_list":"K45SDTL4BGIT93MVEPM1,EK60TLDMP1G26WD2G38R,CS0OMSFOS8UB480KP7UY,ME9D9RFU69B79YLM6V9J,N8CPA3WOWGBPFH6M1VUV","material_code":"40010101000999","restock_qty":0,"material_code_show":"E0批零免漆(测试白标)","unit_code":"ST","unit_code_show":"张","qty":"5","fake_qty":"5","make_qty":"5","bus_type_dk":"SALE_ORDER","bus_type_dk_show":"销售订单","bus_no":"599057977894375424","bus_no_show":"SO202407110062","mat_material_a":{"mat_category_code_show":"免漆板1800香杉木","mat_category_code":"BC020202","cpdj_show":"尊贵型","cpdj":"cpdj01","grade_show":"E0","grade":"01"}}]},{"in_out_type_code":"CK00004","in_out_type_code_show":"商标仓正常领标出库","send_box_code":"CK00018","send_box_code_show":"商标十五号仓","device_code":"DV00001","get_brand_source_dk":"SALE_ORDER","abnormal_flag":false,"abnormal_date":"2024-08-26T16:53:29.109Z","brand_out_stock_dtl":[{"item_no":10,"brand_qr_code_list":"6A51SIUC74AJ8E2JECGP,8VP60YJ5D7C3DX9R93XY,UJ4R8XMJ49AKXQOSW376,8VP6VYJ0CFWRQ49SD3X8,1R6B8DOCUVN67DA2G6A2","material_code":"40010501000999","restock_qty":0,"material_code_show":"银盾抗菌圆标(测试白标)","unit_code":"ST","unit_code_show":"张","qty":"5","fake_qty":"5","make_qty":"5","bus_type_dk":"SALE_ORDER","bus_type_dk_show":"销售订单","bus_no":"599057977894375424","bus_no_show":"SO202407110062","mat_material_a":{"mat_category_code_show":"免漆板1800香杉木","mat_category_code":"BC020202","cpdj_show":"尊贵型","cpdj":"cpdj01","grade_show":"E0","grade":"01"}}]}]}}} ';
- $data = json_decode($data,true);
- $data = $data['param'];
- // $data = $this->data;
- $dv = $data['key'];
- $return = $box_list = [];
- LabelDealService::getInstance()->clearData($data,$return,$box_list);
- Log::channel('apiLog')->info('测试--出库(清洗数据)', ["param" => $return]);
- //调用外部方法
- list($lead_bind,$lead_out) = DwyService::getInstance()->setBoxData1('Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiI1OTAwNDY0ODg5NDAzODQyNTYiLCJhdXRoIjoiUk9MRV9PVVRFUl9VU0VSLFJPTEVfSU5URVJGQUNFLFJPTEVfU0VORF9CUkFORF9TVVBQTElFUixST0xFX1VTRV9CUkFORF9TVVBQTElFUixST0xFX0JSQU5EX1NVUFBMSUVSLFJPTEVfSU5ORVJfVVNFUiIsInRva2VuSWQiOiIzIiwiZXhwIjoxNzI3MjUzMjE0fQ.ucMycX2b2Nzcc4tF0ZPcYDW8QOmqX942MLdmcd3PLa5O4DAseRHkAtyiPxzGf8cIj2qWppGcjusP5c4f0RyDig',$dv,$return,$box_list,$data);
- die;
- //删除限制
- DwyService::getInstance()->delLimitForBoxOut($lead_bind);
- //调用保存接口 cs todo
- LabelDealService::getInstance()->boxOut1($lead_bind,$lead_out,$this->header,$this->id);
- }
- public function encryption($jsonToString, $saltKey, $aesEncRequestKey) {
- $this->aesKey = $aesEncRequestKey;
- $this->saltIVKey = $saltKey;
- return $this->encryptJsonData($jsonToString);
- }
- public function decryption($encryptedResponseData, $saltKey, $aesEncRequestKey) {
- $this->aesKey = $aesEncRequestKey;
- $this->saltIVKey = $saltKey;
- return $this->decryptResponseData($encryptedResponseData);
- }
- private function encryptJsonData($jsonToString) {
- $saltBytes = $this->saltIVKey;
- $secretKey = $this->generateSecretKey($this->aesKey, $saltBytes);
- $cipher = "AES-256-CBC";
- $encryptedTextBytes = openssl_encrypt($jsonToString, $cipher, $secretKey, OPENSSL_RAW_DATA, $this->ivBytes);
- return $this->byteToHex($encryptedTextBytes);
- }
- private function decryptResponseData($encryptedResponseData) {
- $saltBytes = $this->saltIVKey;
- $encryptedTextBytes = $this->hex2ByteArray($encryptedResponseData);
- $secretKey = $this->generateSecretKey($this->aesKey, $saltBytes);
- $cipher = "AES-256-CBC";
- $decryptedTextBytes = openssl_decrypt($encryptedTextBytes, $cipher, $secretKey, OPENSSL_RAW_DATA, $this->ivBytes);
- return $decryptedTextBytes;
- }
- private function generateSecretKey($aesKey, $saltBytes) {
- return hash_pbkdf2("sha1", $aesKey, $saltBytes, 65536, 32, true);
- }
- private function byteToHex($byData) {
- return strtoupper(bin2hex($byData));
- }
- private function hex2ByteArray($sHexData) {
- return hex2bin($sHexData);
- }
- }
|