RsApi.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <?php
  2. namespace app\admin\api;
  3. use OneSm\Sm4;
  4. class RsApi {
  5. private $key;
  6. private $iv;
  7. private $clientId;
  8. private $sjhjLog;
  9. private $sm4;
  10. public function __construct()
  11. {
  12. $this->key = 'b123d075924b4224';
  13. $this->iv = '8a003e84b5be7b6e';
  14. $this->clientId = 'jjrzzb';
  15. $this->sjhjLog = [
  16. 'requestIpAddr' => '10.41.18.18',
  17. 'requestMacAddr' => '28:6e:d4:88:cb:98',
  18. 'requestReason' => '申报系统审核',
  19. 'operaterName' => '系统',
  20. 'operaterIdcard' => '123456789'
  21. ];
  22. $this->sm4 = new Sm4($this->key);
  23. }
  24. protected function check(){
  25. $deny_list = ["jjrcw.test", "jjrcw.test:8080","report.com","report.jinjianghc.com"]; //拒绝短信名单
  26. if (in_array($_SERVER["HTTP_HOST"], $deny_list))
  27. return false; //测试不请求数据
  28. else
  29. return true;
  30. }
  31. protected function getInfo($url,$data){
  32. $encrypt_str = date("YmdHis",time()) . json_encode($data,JSON_UNESCAPED_UNICODE);
  33. $encrypt_data = $this->sm4->enDataCbc($encrypt_str, $this->iv);
  34. $res = $this->RsCurl('http://172.29.133.70:58080/service-proxy/proxy/'.$url,base64_encode($encrypt_data));
  35. $decrypt_data = $this->sm4->deDataCbc(base64_decode($res), $this->iv);
  36. $decrypt_data = mb_substr($decrypt_data, 14, strlen($decrypt_data), 'UTF-8');
  37. return $decrypt_data;
  38. }
  39. private function RsCurl($url, $postFields){
  40. $ch = curl_init();
  41. curl_setopt($ch, CURLOPT_URL, $url);
  42. curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  43. 'Content-Type: application/json; charset=utf-8', //json版本需要填写 Content-Type: application/json;
  44. 'clientId: jjrzzb',
  45. 'sysClientCache: false',
  46. 'serviceProxyCache: false',
  47. 'resultCache: false'
  48. )
  49. );
  50. curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); //若果报错 name lookup timed out 报错时添加这一行代码
  51. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  52. curl_setopt($ch, CURLOPT_POST, 1);
  53. curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
  54. curl_setopt($ch, CURLOPT_TIMEOUT, 60);
  55. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  56. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  57. $ret = curl_exec($ch);
  58. if (false == $ret) {
  59. $result = curl_error($ch);
  60. } else {
  61. $rsp = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  62. if (200 != $rsp) {
  63. $result = "请求状态 " . $rsp . " " . curl_error($ch);
  64. } else {
  65. $result = $ret;
  66. }
  67. }
  68. curl_close($ch);
  69. return $result;
  70. }
  71. /**
  72. * 根据身份证号码查询身份证信息
  73. * @param $card
  74. */
  75. public function I010902($card){
  76. $check_res = $this->check();
  77. if(!$check_res) return ['code' => '403','message' => '测试环境'];
  78. $param = [
  79. 'userIDCard' => '聚才网',
  80. 'queryCause' => '聚才网人员信息核查',
  81. 'reqIp' => '10.41.18.18',
  82. 'QQF_MAC' => '28:6e:d4:88:cb:98',
  83. 'userName' => '聚才网',
  84. 'approvePhone' => '18060002035',
  85. 'BHCR_SFZH' => $card,
  86. 'sjhjLog' => $this->sjhjLog
  87. ];
  88. $res = $this->getInfo('I010902',$param);
  89. return json_decode($res,true);
  90. }
  91. /**
  92. * 根据身份证号码查询个人婚姻信息
  93. * @param $card
  94. * @return array|mixed
  95. */
  96. public function I030101($card){
  97. $check_res = $this->check();
  98. if(!$check_res) return ['code' => '403','message' => '测试环境'];
  99. $param = [
  100. 'aac002' => $card,
  101. 'sjhjLog' => $this->sjhjLog
  102. ];
  103. $res = $this->getInfo('I030101',$param);
  104. return json_decode($res,true);
  105. }
  106. public function I110202($card,$time){
  107. $check_res = $this->check();
  108. if(!$check_res) return ['code' => '403','message' => '测试环境'];
  109. $param = [
  110. 'zjhm' => $card,
  111. 'ny' => $time,
  112. 'sjhjLog' => $this->sjhjLog
  113. ];
  114. $res = $this->getInfo('I110202',$param);
  115. return json_decode($res,true);
  116. }
  117. /**
  118. * 根据统一社会信用代码查询企业基本信息
  119. * @param $idCard
  120. */
  121. public function I040102($idCard){
  122. $check_res = $this->check();
  123. if(!$check_res) return ['code' => '403','message' => '测试环境'];
  124. $param = [
  125. 'USCC' => $idCard,
  126. 'sjhjLog' => $this->sjhjLog
  127. ];
  128. $res = $this->getInfo('I040102',$param);
  129. return json_decode($res,true);
  130. }
  131. }