* @version : HUOUNION 8.5 */ namespace huoIdentify\identifyDriver\driver; use huoIdentify\identifyDriver\Driver; use huolib\status\CommonStatus; use think\Config; use think\Log; class Alipay extends Driver { /** * 构造函数 * * @param array $config */ public function __construct($config = []) { if (empty($config)) { $config = (array) Config::get('identify_conf.alipay'); } $_config = array( 'appCode' => get_val($config, 'APP_CODE', ''), ); parent::__construct($_config); } /** * 获取认证 * * 阿里云市场认证接口 * https://market.aliyun.com/products/57000002/cmapi026109.html?spm=5176.10695662.1996646101.searchclickresult.215b15faGVm5dx#sku=yuncode2010900006 */ public function identify() { // 云市场分配的应用code $appCode = $this->config['appCode']; $host = "https://eid.shumaidata.com"; $path = "/eid/check"; $method = "POST"; $headers = array(); array_push($headers, "Authorization:APPCODE ".$appCode); $querys = 'idcard='.$this->id_card.'&name='.$this->real_name; $url = $host.$path."?".$querys; $curl = curl_init(); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); curl_setopt($curl, CURLOPT_FAILONERROR, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HEADER, false); if (1 == strpos("$".$host, "https://")) { curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); } $_rs_json = curl_exec($curl); curl_close($curl); $_rs = json_decode($_rs_json, true); if (empty($_rs)) { Log::write( 'line='.__LINE__.'&func='.__FUNCTION__.'&class='.__CLASS__.'¶m='.json_encode( array($this->config, $this->id_card, $this->real_name) ).'&rs='.$_rs_json.'[阿里云实名认证api1]', Log::ERROR ); $_code = CommonStatus::INVALID_PARAMS; return $this->huoError($_code, CommonStatus::getMsg($_code)); } if (isset($_rs['code']) && 0 != $_rs['code']) { Log::write( 'line='.__LINE__.'&func='.__FUNCTION__.'&class='.__CLASS__.'¶m='.json_encode( array($this->config, $this->id_card, $this->real_name) ).'&rs='.$_rs_json.'[阿里云实名认证api2]', Log::ERROR ); return $this->huoError($_rs['code'], $_rs['message']); } if (isset($_rs['result']['res']) && 1 != $_rs['result']['res']) { Log::write( 'line='.__LINE__.'&func='.__FUNCTION__.'&class='.__CLASS__.'¶m='.json_encode( array($this->config, $this->id_card, $this->real_name) ).'&rs='.$_rs_json.'[阿里云实名认证api3]', Log::ERROR ); $_code = CommonStatus::INNER_ERROR; return $this->huoError($_code, $_rs['result']['description']); } $_code = CommonStatus::NO_ERROR; return $this->huoSuccess($_code, CommonStatus::getMsg($_code)); } }