首页 > 技术文章 > 支付宝芝麻认证,demo,

jackduan 2017-07-17 14:04 原文

//个人认证使用芝麻认证
public function zhima(){
vendor('alipay.alipayapp.AopSdk');
$alipay_config = C('alipay_config');
$aop = new \AopClient ();
$aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
$aop->appId = $alipay_config['app_id'];
$aop->rsaPrivateKey = $alipay_config['private_key'];
$aop->alipayrsaPublicKey = $alipay_config['public_key'];
$aop->apiVersion = '1.0';
$aop->signType = 'RSA2';
$aop->postCharset='UTF-8';
$aop->format='json';
$request = new \ZhimaCustomerCertificationInitializeRequest ();
$uid = $this->userid;
$transaction_id = date('Ymd') . $uid . uniqid();
$cert_name = $_POST['cert_name'];
$cert_no = $_POST['cert_no'];
$request->setBizContent("{" .
"\"transaction_id\":\"$transaction_id\"," .
"\"product_code\":\"w1010100000000002978\"," .
"\"biz_code\":\"FACE\"," .
"\"identity_param\":\"{\\\"identity_type\\\":\\\"CERT_INFO\\\",\\\"cert_type\\\":\\\"IDENTITY_CARD\\\",\\\"cert_name\\\":\\\"$cert_name\\\",\\\"cert_no\\\":\\\"$cert_no\\\"}\"," .
"\"ext_biz_param\":\"{}\"" .
" }");
$result = $aop->execute ( $request);
$responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
$resultCode = $result->$responseNode->code;
if(!empty($resultCode)&&$resultCode == 10000){
$res['biz_no'] = $result->$responseNode->biz_no;
$res['status'] = '1';
$this->ajaxReturn($res);
} else {
$res['status'] = '0';
$this->ajaxReturn($res);
}
}
//芝麻认证查询
public function zhimaquery(){
vendor('alipay.alipayapp.AopSdk');
$alipay_config = C('alipay_config');
$aop = new \AopClient ();
$aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
$aop->appId = $alipay_config['app_id'];
$aop->rsaPrivateKey = $alipay_config['private_key'];
$aop->alipayrsaPublicKey = $alipay_config['public_key'];
$aop->apiVersion = '1.0';
$aop->signType = 'RSA2';
$aop->postCharset='UTF-8';
$aop->format='json';
$biz_no = $_POST['biz_no'];
$request = new \ZhimaCustomerCertificationQueryRequest ();
$request->setBizContent("{" .
"\"biz_no\":\"$biz_no\"" .
" }");
$result = $aop->execute ( $request);
$responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
$resultCode = $result->$responseNode->code;
if(!empty($resultCode)&&$resultCode == 10000){
$res['passed'] = $result->$responseNode->passed;
$res['status'] = '1';
$this->ajaxReturn($res);
} else {
$res['passed'] = 'false';
$res['status'] = '0';
$this->ajaxReturn($res);
}
}
//开始认证
public function zhimaiden(){
vendor('alipay.alipayapp.AopSdk');
$alipay_config = C('alipay_config');
$aop = new \AopClient ();
$aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
$aop->appId = $alipay_config['app_id'];
$aop->rsaPrivateKey = $alipay_config['private_key'];
$aop->alipayrsaPublicKey = $alipay_config['public_key'];
$aop->apiVersion = '1.0';
$aop->signType = 'RSA2';
$aop->postCharset='UTF-8';
$aop->format='json';
$biz_no = $_POST['biz_no'];
$request = new \ZhimaCustomerCertificationCertifyRequest ();
$request->setBizContent("{" .
"\"biz_no\":\"$biz_no\"" .
" }");
$request->setReturnUrl("alipays://www.taobao.com"); //认证回调接口?
$test = $aop->pageExecute($request,"GET");
$test = base64_encode($test);
if($test){
//转成二维码
$src = U("iden/zhimaqrcode", array("url" =>$test));
$res['data'] = $src;
$res['status'] = '1';
$this->ajaxReturn($res);

}else{
$res['status'] = '0';
$this->ajaxReturn($res);
}

}
public function zhimaqrcode(){
Vendor('WxpayAPI.example.qrcode');
$qrcode = new \QRcode();
$test = base64_decode($_GET['url']);
$qrcode->png($test,false);
}

推荐阅读