添加微信支付实名验证相关接口的核心实现
Co-authored-by: binarywang <1343140+binarywang@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
package com.github.binarywang.wxpay.bean.realname;
|
||||
|
||||
import com.github.binarywang.wxpay.bean.request.BaseWxPayRequest;
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
import lombok.*;
|
||||
import me.chanjar.weixin.common.annotation.Required;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 微信支付实名验证请求对象.
|
||||
* 详见文档:https://pay.wechatpay.cn/doc/v2/merchant/4011987607
|
||||
* </pre>
|
||||
*
|
||||
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Builder(builderMethodName = "newBuilder")
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@XStreamAlias("xml")
|
||||
public class RealNameRequest extends BaseWxPayRequest {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 字段名:用户标识
|
||||
* 变量名:openid
|
||||
* 是否必填:是
|
||||
* 类型:String(128)
|
||||
* 示例值:oUpF8uMuAJO_M2pxb1Q9zNjWeS6o
|
||||
* 描述:用户在商户appid下的唯一标识
|
||||
* </pre>
|
||||
*/
|
||||
@Required
|
||||
@XStreamAlias("openid")
|
||||
private String openid;
|
||||
|
||||
@Override
|
||||
protected void checkConstraints() {
|
||||
//do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void storeMap(Map<String, String> map) {
|
||||
map.put("openid", openid);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package com.github.binarywang.wxpay.bean.realname;
|
||||
|
||||
import com.github.binarywang.wxpay.bean.result.BaseWxPayResult;
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 微信支付实名验证返回结果.
|
||||
* 详见文档:https://pay.wechatpay.cn/doc/v2/merchant/4011987607
|
||||
* </pre>
|
||||
*
|
||||
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@NoArgsConstructor
|
||||
@XStreamAlias("xml")
|
||||
public class RealNameResult extends BaseWxPayResult implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 字段名:用户标识
|
||||
* 变量名:openid
|
||||
* 是否必填:否
|
||||
* 类型:String(128)
|
||||
* 示例值:oUpF8uMuAJO_M2pxb1Q9zNjWeS6o
|
||||
* 描述:用户在商户appid下的唯一标识
|
||||
* </pre>
|
||||
*/
|
||||
@XStreamAlias("openid")
|
||||
private String openid;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 字段名:实名认证状态
|
||||
* 变量名:is_certified
|
||||
* 是否必填:是
|
||||
* 类型:String(1)
|
||||
* 示例值:Y
|
||||
* 描述:Y-已实名认证 N-未实名认证
|
||||
* </pre>
|
||||
*/
|
||||
@XStreamAlias("is_certified")
|
||||
private String isCertified;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 字段名:实名认证信息
|
||||
* 变量名:cert_info
|
||||
* 是否必填:否
|
||||
* 类型:String(256)
|
||||
* 示例值:
|
||||
* 描述:实名认证的相关信息,如姓名等(加密)
|
||||
* </pre>
|
||||
*/
|
||||
@XStreamAlias("cert_info")
|
||||
private String certInfo;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 字段名:引导链接
|
||||
* 变量名:guide_url
|
||||
* 是否必填:否
|
||||
* 类型:String(256)
|
||||
* 示例值:
|
||||
* 描述:未实名时,引导用户进行实名认证的URL
|
||||
* </pre>
|
||||
*/
|
||||
@XStreamAlias("guide_url")
|
||||
private String guideUrl;
|
||||
|
||||
/**
|
||||
* 从XML结构中加载额外的属性
|
||||
*
|
||||
* @param d Document
|
||||
*/
|
||||
@Override
|
||||
protected void loadXml(Document d) {
|
||||
openid = readXmlString(d, "openid");
|
||||
isCertified = readXmlString(d, "is_certified");
|
||||
certInfo = readXmlString(d, "cert_info");
|
||||
guideUrl = readXmlString(d, "guide_url");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.github.binarywang.wxpay.service;
|
||||
|
||||
import com.github.binarywang.wxpay.bean.realname.RealNameRequest;
|
||||
import com.github.binarywang.wxpay.bean.realname.RealNameResult;
|
||||
import com.github.binarywang.wxpay.exception.WxPayException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 微信支付实名验证相关服务类.
|
||||
* 详见文档:https://pay.wechatpay.cn/doc/v2/merchant/4011987607
|
||||
* </pre>
|
||||
*
|
||||
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
||||
*/
|
||||
public interface RealNameService {
|
||||
/**
|
||||
* <pre>
|
||||
* 获取用户实名认证信息API.
|
||||
* 用于商户查询用户的实名认证状态,如果用户未实名认证,会返回引导用户实名认证的URL
|
||||
* 文档详见:https://pay.wechatpay.cn/doc/v2/merchant/4011987607
|
||||
* 接口链接:https://api.mch.weixin.qq.com/userinfo/realnameauth/query
|
||||
* </pre>
|
||||
*
|
||||
* @param request 请求对象
|
||||
* @return 实名认证查询结果
|
||||
* @throws WxPayException the wx pay exception
|
||||
*/
|
||||
RealNameResult queryRealName(RealNameRequest request) throws WxPayException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 获取用户实名认证信息API(简化方法).
|
||||
* 用于商户查询用户的实名认证状态,如果用户未实名认证,会返回引导用户实名认证的URL
|
||||
* 文档详见:https://pay.wechatpay.cn/doc/v2/merchant/4011987607
|
||||
* 接口链接:https://api.mch.weixin.qq.com/userinfo/realnameauth/query
|
||||
* </pre>
|
||||
*
|
||||
* @param openid 用户openid
|
||||
* @return 实名认证查询结果
|
||||
* @throws WxPayException the wx pay exception
|
||||
*/
|
||||
RealNameResult queryRealName(String openid) throws WxPayException;
|
||||
}
|
||||
@@ -1706,4 +1706,11 @@ public interface WxPayService {
|
||||
* @return the partner pay score sign plan service
|
||||
*/
|
||||
PartnerPayScoreSignPlanService getPartnerPayScoreSignPlanService();
|
||||
|
||||
/**
|
||||
* 获取实名验证服务类
|
||||
*
|
||||
* @return the real name service
|
||||
*/
|
||||
RealNameService getRealNameService();
|
||||
}
|
||||
|
||||
@@ -139,6 +139,9 @@ public abstract class BaseWxPayServiceImpl implements WxPayService {
|
||||
@Getter
|
||||
private final BusinessOperationTransferService businessOperationTransferService = new BusinessOperationTransferServiceImpl(this);
|
||||
|
||||
@Getter
|
||||
private final RealNameService realNameService = new RealNameServiceImpl(this);
|
||||
|
||||
protected Map<String, WxPayConfig> configMap = new ConcurrentHashMap<>();
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.github.binarywang.wxpay.service.impl;
|
||||
|
||||
import com.github.binarywang.wxpay.bean.realname.RealNameRequest;
|
||||
import com.github.binarywang.wxpay.bean.realname.RealNameResult;
|
||||
import com.github.binarywang.wxpay.bean.result.BaseWxPayResult;
|
||||
import com.github.binarywang.wxpay.exception.WxPayException;
|
||||
import com.github.binarywang.wxpay.service.RealNameService;
|
||||
import com.github.binarywang.wxpay.service.WxPayService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 微信支付实名验证相关服务实现类.
|
||||
* 详见文档:https://pay.wechatpay.cn/doc/v2/merchant/4011987607
|
||||
* </pre>
|
||||
*
|
||||
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
public class RealNameServiceImpl implements RealNameService {
|
||||
private final WxPayService payService;
|
||||
|
||||
@Override
|
||||
public RealNameResult queryRealName(RealNameRequest request) throws WxPayException {
|
||||
request.checkAndSign(this.payService.getConfig());
|
||||
String url = this.payService.getPayBaseUrl() + "/userinfo/realnameauth/query";
|
||||
|
||||
String responseContent = this.payService.post(url, request.toXML(), true);
|
||||
RealNameResult result = BaseWxPayResult.fromXML(responseContent, RealNameResult.class);
|
||||
result.checkResult(this.payService, request.getSignType(), true);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RealNameResult queryRealName(String openid) throws WxPayException {
|
||||
RealNameRequest request = RealNameRequest.newBuilder()
|
||||
.openid(openid)
|
||||
.build();
|
||||
return this.queryRealName(request);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user