1
0
mirror of synced 2025-12-21 16:38:01 +08:00

添加微信支付实名验证相关接口的核心实现

Co-authored-by: binarywang <1343140+binarywang@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2025-12-19 17:26:41 +00:00
parent bf4afdc2d4
commit e546bb3ad9
6 changed files with 235 additions and 0 deletions

View File

@@ -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);
}
}

View File

@@ -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");
}
}

View File

@@ -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;
}

View File

@@ -1706,4 +1706,11 @@ public interface WxPayService {
* @return the partner pay score sign plan service
*/
PartnerPayScoreSignPlanService getPartnerPayScoreSignPlanService();
/**
* 获取实名验证服务类
*
* @return the real name service
*/
RealNameService getRealNameService();
}

View File

@@ -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

View File

@@ -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);
}
}