RsApi.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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' => '系统'
  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. }
  29. protected function getInfo($url,$data){
  30. $encrypt_str = date("YmdHis",time()) . json_encode($data,JSON_UNESCAPED_UNICODE);
  31. $encrypt_data = $this->sm4->enDataCbc($encrypt_str, $this->iv);
  32. $res = $this->RsCurl('http://172.29.133.70:58080/service-proxy/proxy/'.$url,base64_encode($encrypt_data));
  33. $decrypt_data = $this->sm4->deDataCbc(base64_decode($res), $this->iv);
  34. $decrypt_data = mb_substr($decrypt_data, 14, strlen($decrypt_data), 'UTF-8');
  35. return $decrypt_data;
  36. }
  37. private function RsCurl($url, $postFields){
  38. $ch = curl_init();
  39. curl_setopt($ch, CURLOPT_URL, $url);
  40. curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  41. 'Content-Type: application/json; charset=utf-8', //json版本需要填写 Content-Type: application/json;
  42. 'clientId: jjrzzb',
  43. 'sysClientCache: false',
  44. 'serviceProxyCache: false',
  45. 'resultCache: false'
  46. )
  47. );
  48. curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); //若果报错 name lookup timed out 报错时添加这一行代码
  49. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  50. curl_setopt($ch, CURLOPT_POST, 1);
  51. curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
  52. curl_setopt($ch, CURLOPT_TIMEOUT, 60);
  53. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  54. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  55. $ret = curl_exec($ch);
  56. if (false == $ret) {
  57. $result = curl_error($ch);
  58. } else {
  59. $rsp = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  60. if (200 != $rsp) {
  61. $result = "请求状态 " . $rsp . " " . curl_error($ch);
  62. } else {
  63. $result = $ret;
  64. }
  65. }
  66. curl_close($ch);
  67. return $result;
  68. }
  69. /**
  70. * 根据身份证号码查询身份证信息
  71. * @param $card
  72. */
  73. public function I010902($card){
  74. $check_res = $this->check();
  75. if(!$check_res) return ['code' => '403','message' => '测试环境'];
  76. $param = [
  77. 'userIDCard' => '聚才网',
  78. 'queryCause' => '聚才网人员信息核查',
  79. 'reqIp' => '10.41.18.18',
  80. 'QQF_MAC' => '28:6e:d4:88:cb:98',
  81. 'userName' => '聚才网',
  82. 'approvePhone' => '18060002035',
  83. 'BHCR_SFZH' => $card,
  84. 'sjhjLog' => $this->sjhjLog
  85. ];
  86. $res = $this->getInfo('I010902',$param);
  87. return json_decode($res,true);
  88. }
  89. }