TestController.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use App\Model\BoxDetail;
  4. use App\Service\Box\BoxHookService;
  5. use App\Service\DwyService;
  6. use App\Service\LabelDealService;
  7. use App\Service\MeasureService;
  8. use Illuminate\Http\Request;
  9. use Illuminate\Support\Facades\Log;
  10. class TestController extends BaseController
  11. {
  12. private $ivBytes = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F";
  13. public function deviceCallback(Request $request){
  14. $sign = $this->makeSign(['appid'=>'ehiV145x0sq2pIdR'],'zcJOeS7Ty1Zk5sEYQ36ia9UbDxWgGRlm');
  15. // var_dump($sign);
  16. var_dump($sign);die;
  17. }
  18. function makeSign($params,$appkey,$sign_type=1){
  19. ksort($params);
  20. unset($params['sign']);
  21. $str = '';
  22. foreach($params as $key=>$val){
  23. if(is_array($val)){
  24. continue;
  25. }
  26. if($sign_type == 1 || !$sign_type){
  27. if(strlen($val) > 0){
  28. $str.= trim($val);
  29. }
  30. }else{
  31. if(strlen($val) > 0){
  32. $str.= trim($key).'='.trim($val);
  33. }
  34. }
  35. }
  36. $hash_hmac = hash_hmac('sha256', $str, $appkey, true);
  37. return urlencode(base64_encode($hash_hmac));
  38. }
  39. public function boxInsert(){
  40. $data = [
  41. 'out_order_no' => 'test123',
  42. 'ext_1' => '1',
  43. 'ext_2' => '2',
  44. 'ext_3' => '3',
  45. 'ext_4' => '4',
  46. 'ext_5' => '5',
  47. 'detail' => [
  48. [
  49. 'top_id' => '1',
  50. 'code' => '001',
  51. 'title' => '产品名称',
  52. 'ext_1' => '1',
  53. 'ext_2' => '2',
  54. 'ext_3' => '3',
  55. 'ext_4' => '4',
  56. 'ext_5' => '5',
  57. ],[
  58. 'top_id' => '2',
  59. 'code' => '002',
  60. 'title' => '产品名称1',
  61. 'ext_1' => '11',
  62. 'ext_2' => '22',
  63. 'ext_3' => '33',
  64. 'ext_4' => '44',
  65. 'ext_5' => '55',
  66. ],
  67. ],
  68. ];
  69. $service = BoxHookService::getInstance();
  70. list($status,$msg) = $service->boxInsert($data);
  71. var_dump($status);
  72. var_dump($msg);
  73. }
  74. public function aa(){
  75. //处理数据
  76. $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"}}]}]}}} ';
  77. $data = json_decode($data,true);
  78. $data = $data['param'];
  79. // $data = $this->data;
  80. $dv = $data['key'];
  81. $return = $box_list = [];
  82. LabelDealService::getInstance()->clearData($data,$return,$box_list);
  83. Log::channel('apiLog')->info('测试--出库(清洗数据)', ["param" => $return]);
  84. //调用外部方法
  85. list($lead_bind,$lead_out) = DwyService::getInstance()->setBoxData1('Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiI1OTAwNDY0ODg5NDAzODQyNTYiLCJhdXRoIjoiUk9MRV9PVVRFUl9VU0VSLFJPTEVfSU5URVJGQUNFLFJPTEVfU0VORF9CUkFORF9TVVBQTElFUixST0xFX1VTRV9CUkFORF9TVVBQTElFUixST0xFX0JSQU5EX1NVUFBMSUVSLFJPTEVfSU5ORVJfVVNFUiIsInRva2VuSWQiOiIzIiwiZXhwIjoxNzI3MjUzMjE0fQ.ucMycX2b2Nzcc4tF0ZPcYDW8QOmqX942MLdmcd3PLa5O4DAseRHkAtyiPxzGf8cIj2qWppGcjusP5c4f0RyDig',$dv,$return,$box_list,$data);
  86. die;
  87. //删除限制
  88. DwyService::getInstance()->delLimitForBoxOut($lead_bind);
  89. //调用保存接口 cs todo
  90. LabelDealService::getInstance()->boxOut1($lead_bind,$lead_out,$this->header,$this->id);
  91. }
  92. public function encryption($jsonToString, $saltKey, $aesEncRequestKey) {
  93. $this->aesKey = $aesEncRequestKey;
  94. $this->saltIVKey = $saltKey;
  95. return $this->encryptJsonData($jsonToString);
  96. }
  97. public function decryption($encryptedResponseData, $saltKey, $aesEncRequestKey) {
  98. $this->aesKey = $aesEncRequestKey;
  99. $this->saltIVKey = $saltKey;
  100. return $this->decryptResponseData($encryptedResponseData);
  101. }
  102. private function encryptJsonData($jsonToString) {
  103. $saltBytes = $this->saltIVKey;
  104. $secretKey = $this->generateSecretKey($this->aesKey, $saltBytes);
  105. $cipher = "AES-256-CBC";
  106. $encryptedTextBytes = openssl_encrypt($jsonToString, $cipher, $secretKey, OPENSSL_RAW_DATA, $this->ivBytes);
  107. return $this->byteToHex($encryptedTextBytes);
  108. }
  109. private function decryptResponseData($encryptedResponseData) {
  110. $saltBytes = $this->saltIVKey;
  111. $encryptedTextBytes = $this->hex2ByteArray($encryptedResponseData);
  112. $secretKey = $this->generateSecretKey($this->aesKey, $saltBytes);
  113. $cipher = "AES-256-CBC";
  114. $decryptedTextBytes = openssl_decrypt($encryptedTextBytes, $cipher, $secretKey, OPENSSL_RAW_DATA, $this->ivBytes);
  115. return $decryptedTextBytes;
  116. }
  117. private function generateSecretKey($aesKey, $saltBytes) {
  118. return hash_pbkdf2("sha1", $aesKey, $saltBytes, 65536, 32, true);
  119. }
  120. private function byteToHex($byData) {
  121. return strtoupper(bin2hex($byData));
  122. }
  123. private function hex2ByteArray($sHexData) {
  124. return hex2bin($sHexData);
  125. }
  126. }