CTCard.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 , config::HeaderProduction, $net_errno);
  48. if (empty($resp)) {
  49. return [false, '网络错误',''];
  50. }
  51. else
  52. {
  53. $resp = json_decode($resp, true);
  54. Log::record($resp, Log::DEBUG);
  55. if (empty($resp)) {
  56. return [false, 'Net Error.',''];
  57. }
  58. $head = $resp['head'] ?? [];
  59. $biz = $resp['biz'] ?? [];
  60. return [true,$head,$biz];
  61. }
  62. }
  63. public function fraud_check($biz) : void
  64. {
  65. [$succ, $head, $biz] = $this->request('fraudCheck', $biz, $net_errno);
  66. }
  67. public function number_list($biz) : void
  68. {
  69. [$succ, $head, $biz] = $this->request('qryNbrList', $biz, $net_errno);
  70. }
  71. public function address_delivery($biz) : void
  72. {
  73. [$succ, $head, $biz] = $this->request('qryReceiveAddr', $biz, $net_errno);
  74. }
  75. public function broadband_address_list($biz) : void
  76. {
  77. [$succ, $head, $biz] = $this->request('qryAddressInfo', $biz, $net_errno);
  78. }
  79. public function broadband_address_resource_query($biz) : void
  80. {
  81. [$succ, $head, $biz] = $this->request('getAddressCover', $biz, $net_errno);
  82. }
  83. public function logistics_path_query($biz) : void
  84. {
  85. [$succ, $head, $biz] = $this->request('getLogisticsTrajectory', $biz, $net_errno);
  86. }
  87. public function add_order($biz) : void
  88. {
  89. [$succ, $head, $biz] = $this->request('synOrderInfo', $biz, $net_errno);
  90. }
  91. public function order_information_query($biz) : void
  92. {
  93. [$succ, $head, $biz] = $this->request('queryOrderInfo', $biz, $net_errno);
  94. }
  95. }