123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- <?php
- namespace mapi;
- require_once(BASE_MAPI_PATH . '/api/ctcard/config.php');
- require_once(BASE_MAPI_PATH . '/api/ctcard/IOpenCard.php');
- use Log;
- class CTCard implements IOpenCard
- {
- private function head($method) : array
- {
- $guider = function (): string
- {
- $str = md5(uniqid(mt_rand(), true));
- $uuid = substr($str, 0, 8);
- $uuid .= substr($str, 8, 4);
- $uuid .= substr($str, 12, 4);
- $uuid .= substr($str, 16, 4);
- $uuid .= substr($str, 20, 12);
- return $uuid;
- };
- $make_sn = function () use ($guider){
- return config::SYS_CODE . config::APP_CODE . date("ymdhm", time()) . $guider();
- };
- $signer = function ($sn) {
- return md5("$sn" . config::KEY);
- };
- $sysCode = config::SYS_CODE;
- $appCode = config::APP_CODE;
- $transactionId = $make_sn();
- $reqTime = date("Y-m-d H:i:s", time());
- $sign = $signer($transactionId);
- return [
- "sysCode"=>$sysCode,
- "appCode"=>$appCode,
- "transactionId"=>$transactionId,
- "reqTime"=>$reqTime,
- "method"=>$method,
- "version"=>"1",
- "attach"=>"hello",
- "sign"=>$sign
- ];
- }
- private function request($head_method,$biz,&$net_errno) : array
- {
- $params['head'] = $this->head($head_method);
- $params['biz'] = $biz;
- $requestParameters = json_encode($params,JSON_UNESCAPED_UNICODE);
- $resp = http_post_data(config::production_env['DcoosExternalNetwork'], $requestParameters , config::HeaderProduction, $net_errno);
- if (empty($resp)) {
- return [false, '网络错误',''];
- }
- else
- {
- $resp = json_decode($resp, true);
- Log::record($resp, Log::DEBUG);
- if (empty($resp)) {
- return [false, 'Net Error.',''];
- }
- $head = $resp['head'] ?? [];
- $biz = $resp['biz'] ?? [];
- return [true,$head,$biz];
- }
- }
- public function fraud_check($biz) : void
- {
- [$succ, $head, $biz] = $this->request('fraudCheck', $biz, $net_errno);
- }
- public function number_list($biz) : void
- {
- [$succ, $head, $biz] = $this->request('qryNbrList', $biz, $net_errno);
- }
- public function address_delivery($biz) : void
- {
- [$succ, $head, $biz] = $this->request('qryReceiveAddr', $biz, $net_errno);
- }
- public function broadband_address_list($biz) : void
- {
- [$succ, $head, $biz] = $this->request('qryAddressInfo', $biz, $net_errno);
- }
- public function broadband_address_resource_query($biz) : void
- {
- [$succ, $head, $biz] = $this->request('getAddressCover', $biz, $net_errno);
- }
- public function logistics_path_query($biz) : void
- {
- [$succ, $head, $biz] = $this->request('getLogisticsTrajectory', $biz, $net_errno);
- }
- public function add_order($biz) : void
- {
- [$succ, $head, $biz] = $this->request('synOrderInfo', $biz, $net_errno);
- }
- public function order_information_query($biz) : void
- {
- [$succ, $head, $biz] = $this->request('queryOrderInfo', $biz, $net_errno);
- }
- }
|