Files
juipphp/alipay/Aliverify.php

214 lines
8.6 KiB
PHP
Raw Normal View History

2020-12-18 14:02:28 +08:00
<?php
namespace alipay;
2020-12-18 14:24:07 +08:00
require_once APP_PATH . 'alipay/aop/AopCertClient.php';
2020-12-18 14:02:28 +08:00
require_once APP_PATH . 'alipay/aop/AopCertification.php';
2020-12-18 14:20:33 +08:00
require_once APP_PATH . 'alipay/aop/request/AlipayUserCertifyOpenInitializeRequest.php';
2020-12-18 14:45:06 +08:00
require_once APP_PATH . 'alipay/aop/request/AlipayUserCertifyOpenCertifyRequest.php';
2020-12-18 21:04:48 +08:00
require_once APP_PATH . 'alipay/aop/request/AlipayUserCertifyOpenQueryRequest.php';
2020-12-18 14:02:28 +08:00
2022-09-28 18:27:13 +08:00
require_once APP_PATH . 'alipay/aop/AopClient.php';
require_once APP_PATH . 'alipay/aop/request/AlipayOpenPublicTemplateMessageIndustryModifyRequest.php';
2020-12-18 14:02:28 +08:00
/**
* 证书类型AopClient功能方法使用测试
* 1、execute 调用示例
* 2、sdkExecute 调用示例
* 3、pageExecute 调用示例
*/
class Aliverify
{
2020-12-18 21:04:48 +08:00
public static function initVerify($temp)
2020-12-18 14:02:28 +08:00
{
global $config;
2020-12-18 14:35:21 +08:00
$aop = new \AopCertClient();
2020-12-18 21:04:48 +08:00
$res = [];
$res['name'] = $temp['name'];
$res['id_code'] = $temp['id_code'];
2020-12-18 14:35:21 +08:00
$appCertPath = $config['alipay']['app_crt'];
$alipayCertPath = $config['alipay']['public_crt'];
$rootCertPath = $config['alipay']['root_crt'];
2020-12-18 14:02:28 +08:00
$aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
$aop->appId = $config['alipay']['app_id'];
$aop->rsaPrivateKey = $config['alipay']['private_key'];
2020-12-18 14:35:21 +08:00
$aop->alipayrsaPublicKey = $aop->getPublicKey($alipayCertPath);//调用getPublicKey从支付宝公钥证书中提取公钥
2020-12-18 14:02:28 +08:00
$aop->apiVersion = '1.0';
$aop->signType = 'RSA2';
2020-12-18 14:35:21 +08:00
$aop->postCharset='utf-8';
$aop->format='json';
$aop->isCheckAlipayPublicCert = true;//是否校验自动下载的支付宝公钥证书,如果开启校验要保证支付宝根证书在有效期内
$aop->appCertSN = $aop->getCertSN($appCertPath);//调用getCertSN获取证书序列号
$aop->alipayRootCertSN = $aop->getRootCertSN($rootCertPath);//调用getRootCertSN获取支付宝根证书序列号
2020-12-18 14:02:28 +08:00
$request = new \AlipayUserCertifyOpenInitializeRequest();
//$request = new AlipayUserCertifyOpenInitializeRequest (); //TODO 官方这个地方写错了,应该用下面的代码才能实现
$newsigndata=array();
$newsigndata['outer_order_no']=md5(time());
$newsigndata['biz_code']="FACE";
$newsigndata['identity_param']['identity_type']="CERT_INFO";
$newsigndata['identity_param']['cert_type']="IDENTITY_CARD";
2020-12-18 21:04:48 +08:00
$newsigndata['identity_param']['cert_name']=$res['name'];
$newsigndata['identity_param']['cert_no']= $res['id_code'];
2021-04-26 16:05:39 +08:00
$newsigndata['merchant_config']['return_url']="http://www.juip.com/User/Index?realname=true";
2020-12-18 14:02:28 +08:00
$newsigndata['face_contrast_picture']="xydasf==";
$tosign=json_encode($newsigndata);
$request->setBizContent($tosign);
$result = $aop->execute ( $request);
$responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
$resultCode = $result->$responseNode->code;
2020-12-18 14:43:50 +08:00
$certify_id = $result->$responseNode->certify_id;
2020-12-18 14:02:28 +08:00
if(!empty($resultCode)&&$resultCode == 10000){
2020-12-18 14:47:27 +08:00
$request = new \AlipayUserCertifyOpenCertifyRequest ();
2020-12-18 14:43:50 +08:00
$data['certify_id'] = $certify_id;
$tosign=json_encode($data);
$request->setBizContent($tosign);
2020-12-18 16:24:48 +08:00
$result = $aop->pageExecute($request,"GET");
2020-12-18 14:43:50 +08:00
2020-12-18 16:24:48 +08:00
$res['certifyId'] = $certify_id;
$res['url'] = $result;
return $res;
2020-12-18 14:02:28 +08:00
} else {
2020-12-18 21:04:48 +08:00
return false;
2020-12-18 14:02:28 +08:00
}
}
2022-09-28 18:27:13 +08:00
2021-04-26 16:05:39 +08:00
public static function getResult($certify_id)
2020-12-18 14:02:28 +08:00
{
global $config;
$aop = new \AopCertClient();
$appCertPath = $config['alipay']['app_crt'];
$alipayCertPath = $config['alipay']['public_crt'];
$rootCertPath = $config['alipay']['root_crt'];
$aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
$aop->appId = $config['alipay']['app_id'];
$aop->rsaPrivateKey = $config['alipay']['private_key'];
$aop->alipayrsaPublicKey = $aop->getPublicKey($alipayCertPath);//调用getPublicKey从支付宝公钥证书中提取公钥
$aop->apiVersion = '1.0';
$aop->signType = 'RSA2';
$aop->postCharset='utf-8';
$aop->format='json';
$aop->isCheckAlipayPublicCert = true;//是否校验自动下载的支付宝公钥证书,如果开启校验要保证支付宝根证书在有效期内
$aop->appCertSN = $aop->getCertSN($appCertPath);//调用getCertSN获取证书序列号
$aop->alipayRootCertSN = $aop->getRootCertSN($rootCertPath);//调用getRootCertSN获取支付宝根证书序列号
2020-12-18 21:41:13 +08:00
$request = new \AlipayUserCertifyOpenQueryRequest ();
2020-12-18 21:04:48 +08:00
$data['certify_id'] = $certify_id;
$tosign=json_encode($data);
$request->setBizContent($tosign);
$result = $aop->execute ( $request);
2020-12-18 14:02:28 +08:00
$responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
2020-12-18 22:00:55 +08:00
$resultCode = $result->$responseNode->passed;
if($resultCode == 'T'){
2021-04-26 16:05:39 +08:00
return true;
2020-12-18 14:02:28 +08:00
} else {
return false;
}
2020-12-18 21:04:48 +08:00
2020-12-18 21:07:53 +08:00
}
2022-09-28 18:27:13 +08:00
public static function initVerify2($temp)
{
global $config;
$res = [];
$res['name'] = $temp['name'];
$res['id_code'] = $temp['id_code'];
$c = new \AopClient;
$c->gatewayUrl = "https://openapi.alipay.com/gateway.do";
$c->appId = $config['alipay2']['app_id'];
$c->rsaPrivateKey = $config['alipay2']['private_key'] ;
$c->format = "json";
$c->charset= "utf-8";
$c->signType= "RSA2";
$c->alipayrsaPublicKey = $config['alipay2']['public_key'];
//实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称alipay.open.public.template.message.industry.modify
2022-09-28 18:55:37 +08:00
$request = new \AlipayUserCertifyOpenInitializeRequest();
//$request = new AlipayUserCertifyOpenInitializeRequest (); //TODO 官方这个地方写错了,应该用下面的代码才能实现
2022-09-28 18:27:13 +08:00
//SDK已经封装掉了公共参数这里只需要传入业务参数
//此次只是参数展示,未进行字符串转义,实际情况下请转义
$newsigndata=array();
$newsigndata['outer_order_no']=md5(time());
$newsigndata['biz_code']="FACE";
$newsigndata['identity_param']['identity_type']="CERT_INFO";
$newsigndata['identity_param']['cert_type']="IDENTITY_CARD";
$newsigndata['identity_param']['cert_name']=$res['name'];
$newsigndata['identity_param']['cert_no']= $res['id_code'];
$newsigndata['merchant_config']['return_url']="http://www.juip.com/User/Index?realname=true";
$newsigndata['face_contrast_picture']="xydasf==";
$tosign=json_encode($newsigndata);
$request->setBizContent($tosign);
$result= $c->execute($request);
$responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
$resultCode = $result->$responseNode->code;
$certify_id = $result->$responseNode->certify_id;
if(!empty($resultCode)&&$resultCode == 10000){
2022-09-28 18:55:37 +08:00
$request = new \AlipayUserCertifyOpenCertifyRequest ();
2022-09-28 18:27:13 +08:00
$data['certify_id'] = $certify_id;
$tosign=json_encode($data);
$request->setBizContent($tosign);
$result = $c->pageExecute($request,"GET");
$res['certifyId'] = $certify_id;
$res['url'] = $result;
return $res;
} else {
return false;
}
}
public static function getResult2($certify_id)
{
//--------------------------------
global $config;
$aop = new \AopClient ();
$aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
$aop->appId = $config['alipay2']['app_id'];;
$aop->rsaPrivateKey = $config['alipay2']['private_key'] ;
2022-09-28 19:19:38 +08:00
$aop->apiVersion = '1.0';
$aop->signType = 'RSA2';
$aop->postCharset='utf-8';
2022-09-28 18:27:13 +08:00
$aop->format='json';
2022-09-28 19:19:38 +08:00
$aop->alipayrsaPublicKey = $config['alipay2']['public_key'];
2022-09-28 19:24:17 +08:00
$request = new \AlipayUserCertifyOpenQueryRequest ();
2022-09-28 18:27:13 +08:00
$data['certify_id'] = $certify_id;
$tosign=json_encode($data);
$request->setBizContent($tosign);
2022-09-28 19:24:17 +08:00
$result = $aop->execute ( $request);
2022-09-28 18:27:13 +08:00
$responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
2022-09-28 19:24:17 +08:00
$resultCode = $result->$responseNode->passed;
if($resultCode == 'T'){
2022-09-28 19:06:08 +08:00
return true;
} else {
return false;
}
2022-09-28 19:19:38 +08:00
// $resultCode = $result->$responseNode->passed;
// if($resultCode == 'T'){
// return true;
// } else {
// return false;
// }
2022-09-28 18:27:13 +08:00
}
2020-12-18 21:04:48 +08:00
2020-12-18 14:02:28 +08:00
}