CTCard.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <?php
  2. namespace mapi;
  3. require_once(BASE_MAPI_PATH . '/api/ctcard/config.php');
  4. require_once(BASE_MAPI_PATH . '/api/ctcard/IOpenCard.php');
  5. use Log;
  6. class CTCard implements IOpenCard
  7. {
  8. private function head($method) : array
  9. {
  10. $guider = function (): string
  11. {
  12. $str = md5(uniqid(mt_rand(), true));
  13. $uuid = substr($str, 0, 8);
  14. $uuid .= substr($str, 8, 4);
  15. $uuid .= substr($str, 12, 4);
  16. $uuid .= substr($str, 16, 4);
  17. $uuid .= substr($str, 20, 12);
  18. return $uuid;
  19. };
  20. $make_sn = function () use ($guider){
  21. return config::SYS_CODE . config::APP_CODE . date("ymdhm", time()) . $guider();
  22. };
  23. $signer = function ($sn) {
  24. return md5("$sn" . config::KEY);
  25. };
  26. $sysCode = config::SYS_CODE;
  27. $appCode = config::APP_CODE;
  28. $transactionId = $make_sn();
  29. $reqTime = date("Y-m-d H:i:s", time());
  30. $sign = $signer($transactionId);
  31. return [
  32. "sysCode"=>$sysCode,
  33. "appCode"=>$appCode,
  34. "transactionId"=>$transactionId,
  35. "reqTime"=>$reqTime,
  36. "method"=>$method,
  37. "version"=>"1",
  38. "attach"=>"hello",
  39. "sign"=>$sign
  40. ];
  41. }
  42. private function request($head_method,$biz,&$net_errno) : array
  43. {
  44. $params['head'] = $this->head($head_method);
  45. $params['biz'] = $biz;
  46. $requestParameters = json_encode($params,JSON_UNESCAPED_UNICODE);
  47. $resp = http_post_data(config::production_env['DcoosExternalNetwork'], $requestParameters,
  48. config::HeaderProduction, $net_errno);
  49. if (empty($resp)) {
  50. return [false, '网络错误',''];
  51. }
  52. else
  53. {
  54. $resp = json_decode($resp, true);
  55. Log::record($resp, Log::DEBUG);
  56. if (empty($resp)) {
  57. return [false, 'Net Error.',''];
  58. }
  59. $head = $resp['head'] ?? [];
  60. $biz = $resp['biz'] ?? [];
  61. return [true,$head,$biz];
  62. }
  63. }
  64. public function fraud_check($biz) : array
  65. {
  66. [$succ, $head, $biz] = $this->request('fraudCheck', $biz, $net_errno);
  67. if($succ)
  68. {
  69. $code = intval($biz['code']);
  70. $msg = $biz['codeMessage'];
  71. if($code == 0) {
  72. return [true,$msg];
  73. } else {
  74. return [false,$msg];
  75. }
  76. }
  77. else {
  78. return [false,'网络错误'];
  79. }
  80. }
  81. public function card_noes($biz) : array
  82. {
  83. [$succ, $head, $biz] = $this->request('qryNbrList', $biz, $net_errno);
  84. if($succ)
  85. {
  86. $code = intval($biz['code']);
  87. $msg = $biz['codeMessage'];
  88. $phones = $biz['phoneList'];
  89. if($code == 2000) {
  90. return [true,$phones];
  91. } else {
  92. return [false,$msg];
  93. }
  94. }
  95. else {
  96. return [false,'网络错误'];
  97. }
  98. }
  99. public function sub_units($biz) : array
  100. {
  101. [$succ, $head, $biz] = $this->request('qryReceiveAddr', $biz, $net_errno);
  102. if($succ)
  103. {
  104. $code = intval($biz['code']);
  105. $msg = $biz['codeMessage'];
  106. $phones = $biz['phoneList'];
  107. if($code == 2000) {
  108. return [true,$phones];
  109. } else {
  110. return [false,$msg];
  111. }
  112. }
  113. else {
  114. return [false,'网络错误'];
  115. }
  116. }
  117. public function broadband_address_list($biz) : void
  118. {
  119. [$succ, $head, $biz] = $this->request('qryAddressInfo', $biz, $net_errno);
  120. }
  121. public function broadband_address_resource_query($biz) : void
  122. {
  123. [$succ, $head, $biz] = $this->request('getAddressCover', $biz, $net_errno);
  124. }
  125. public function logistics_path_query($biz) : void
  126. {
  127. [$succ, $head, $biz] = $this->request('getLogisticsTrajectory', $biz, $net_errno);
  128. }
  129. public function add_order($biz) : void
  130. {
  131. [$succ, $head, $biz] = $this->request('synOrderInfo', $biz, $net_errno);
  132. }
  133. public function order_info($order_sn) : void
  134. {
  135. [$succ, $head, $biz] = $this->request('queryOrderInfo', ['orderCode' => $order_sn], $net_errno);
  136. }
  137. }