Alipay.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /**
  3. * Alipay.php UTF-8
  4. * 阿里云实名认证api
  5. *
  6. * @date : 2020/3/4 10:41
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : chenbingling <cbl@huosdk.com>
  10. * @version : HUOUNION 8.5
  11. */
  12. namespace huoIdentify\identifyDriver\driver;
  13. use huoIdentify\identifyDriver\Driver;
  14. use huolib\status\CommonStatus;
  15. use think\Config;
  16. use think\Log;
  17. class Alipay extends Driver {
  18. /**
  19. * 构造函数
  20. *
  21. * @param array $config
  22. */
  23. public function __construct($config = []) {
  24. if (empty($config)) {
  25. $config = (array) Config::get('identify_conf.alipay');
  26. }
  27. $_config = array(
  28. 'appCode' => get_val($config, 'APP_CODE', ''),
  29. );
  30. parent::__construct($_config);
  31. }
  32. /**
  33. * 获取认证
  34. *
  35. * 阿里云市场认证接口
  36. * https://market.aliyun.com/products/57000002/cmapi026109.html?spm=5176.10695662.1996646101.searchclickresult.215b15faGVm5dx#sku=yuncode2010900006
  37. */
  38. public function identify() {
  39. // 云市场分配的应用code
  40. $appCode = $this->config['appCode'];
  41. $host = "https://eid.shumaidata.com";
  42. $path = "/eid/check";
  43. $method = "POST";
  44. $headers = array();
  45. array_push($headers, "Authorization:APPCODE ".$appCode);
  46. $querys = 'idcard='.$this->id_card.'&name='.$this->real_name;
  47. $url = $host.$path."?".$querys;
  48. $curl = curl_init();
  49. curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
  50. curl_setopt($curl, CURLOPT_URL, $url);
  51. curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
  52. curl_setopt($curl, CURLOPT_FAILONERROR, false);
  53. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  54. curl_setopt($curl, CURLOPT_HEADER, false);
  55. if (1 == strpos("$".$host, "https://")) {
  56. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  57. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  58. }
  59. $_rs_json = curl_exec($curl);
  60. curl_close($curl);
  61. $_rs = json_decode($_rs_json, true);
  62. if (empty($_rs)) {
  63. Log::write(
  64. 'line='.__LINE__.'&func='.__FUNCTION__.'&class='.__CLASS__.'&param='.json_encode(
  65. array($this->config, $this->id_card, $this->real_name)
  66. ).'&rs='.$_rs_json.'[阿里云实名认证api1]', Log::ERROR
  67. );
  68. $_code = CommonStatus::INVALID_PARAMS;
  69. return $this->huoError($_code, CommonStatus::getMsg($_code));
  70. }
  71. if (isset($_rs['code']) && 0 != $_rs['code']) {
  72. Log::write(
  73. 'line='.__LINE__.'&func='.__FUNCTION__.'&class='.__CLASS__.'&param='.json_encode(
  74. array($this->config, $this->id_card, $this->real_name)
  75. ).'&rs='.$_rs_json.'[阿里云实名认证api2]', Log::ERROR
  76. );
  77. return $this->huoError($_rs['code'], $_rs['message']);
  78. }
  79. if (isset($_rs['result']['res']) && 1 != $_rs['result']['res']) {
  80. Log::write(
  81. 'line='.__LINE__.'&func='.__FUNCTION__.'&class='.__CLASS__.'&param='.json_encode(
  82. array($this->config, $this->id_card, $this->real_name)
  83. ).'&rs='.$_rs_json.'[阿里云实名认证api3]', Log::ERROR
  84. );
  85. $_code = CommonStatus::INNER_ERROR;
  86. return $this->huoError($_code, $_rs['result']['description']);
  87. }
  88. $_code = CommonStatus::NO_ERROR;
  89. return $this->huoSuccess($_code, CommonStatus::getMsg($_code));
  90. }
  91. }