From e546bb3ad909122633290256781ffefb3941dbb5 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 19 Dec 2025 17:26:41 +0000 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=BE=AE=E4=BF=A1=E6=94=AF?= =?UTF-8?q?=E4=BB=98=E5=AE=9E=E5=90=8D=E9=AA=8C=E8=AF=81=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E7=9A=84=E6=A0=B8=E5=BF=83=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: binarywang <1343140+binarywang@users.noreply.github.com> --- .../wxpay/bean/realname/RealNameRequest.java | 50 ++++++++++ .../wxpay/bean/realname/RealNameResult.java | 91 +++++++++++++++++++ .../wxpay/service/RealNameService.java | 43 +++++++++ .../wxpay/service/WxPayService.java | 7 ++ .../service/impl/BaseWxPayServiceImpl.java | 3 + .../service/impl/RealNameServiceImpl.java | 41 +++++++++ 6 files changed, 235 insertions(+) create mode 100644 weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/realname/RealNameRequest.java create mode 100644 weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/realname/RealNameResult.java create mode 100644 weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/RealNameService.java create mode 100644 weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/RealNameServiceImpl.java diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/realname/RealNameRequest.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/realname/RealNameRequest.java new file mode 100644 index 000000000..a06318d61 --- /dev/null +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/realname/RealNameRequest.java @@ -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; + +/** + *
+ * 微信支付实名验证请求对象. + * 详见文档:https://pay.wechatpay.cn/doc/v2/merchant/4011987607 + *+ * + * @author Binary Wang + */ +@Data +@EqualsAndHashCode(callSuper = true) +@Builder(builderMethodName = "newBuilder") +@NoArgsConstructor +@AllArgsConstructor +@XStreamAlias("xml") +public class RealNameRequest extends BaseWxPayRequest { + private static final long serialVersionUID = 1L; + + /** + *
+ * 字段名:用户标识 + * 变量名:openid + * 是否必填:是 + * 类型:String(128) + * 示例值:oUpF8uMuAJO_M2pxb1Q9zNjWeS6o + * 描述:用户在商户appid下的唯一标识 + *+ */ + @Required + @XStreamAlias("openid") + private String openid; + + @Override + protected void checkConstraints() { + //do nothing + } + + @Override + protected void storeMap(Map
+ * 微信支付实名验证返回结果. + * 详见文档:https://pay.wechatpay.cn/doc/v2/merchant/4011987607 + *+ * + * @author Binary Wang + */ +@Data +@EqualsAndHashCode(callSuper = true) +@NoArgsConstructor +@XStreamAlias("xml") +public class RealNameResult extends BaseWxPayResult implements Serializable { + private static final long serialVersionUID = 1L; + + /** + *
+ * 字段名:用户标识 + * 变量名:openid + * 是否必填:否 + * 类型:String(128) + * 示例值:oUpF8uMuAJO_M2pxb1Q9zNjWeS6o + * 描述:用户在商户appid下的唯一标识 + *+ */ + @XStreamAlias("openid") + private String openid; + + /** + *
+ * 字段名:实名认证状态 + * 变量名:is_certified + * 是否必填:是 + * 类型:String(1) + * 示例值:Y + * 描述:Y-已实名认证 N-未实名认证 + *+ */ + @XStreamAlias("is_certified") + private String isCertified; + + /** + *
+ * 字段名:实名认证信息 + * 变量名:cert_info + * 是否必填:否 + * 类型:String(256) + * 示例值: + * 描述:实名认证的相关信息,如姓名等(加密) + *+ */ + @XStreamAlias("cert_info") + private String certInfo; + + /** + *
+ * 字段名:引导链接 + * 变量名:guide_url + * 是否必填:否 + * 类型:String(256) + * 示例值: + * 描述:未实名时,引导用户进行实名认证的URL + *+ */ + @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"); + } +} diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/RealNameService.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/RealNameService.java new file mode 100644 index 000000000..d69bda7d3 --- /dev/null +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/RealNameService.java @@ -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; + +/** + *
+ * 微信支付实名验证相关服务类. + * 详见文档:https://pay.wechatpay.cn/doc/v2/merchant/4011987607 + *+ * + * @author Binary Wang + */ +public interface RealNameService { + /** + *
+ * 获取用户实名认证信息API. + * 用于商户查询用户的实名认证状态,如果用户未实名认证,会返回引导用户实名认证的URL + * 文档详见:https://pay.wechatpay.cn/doc/v2/merchant/4011987607 + * 接口链接:https://api.mch.weixin.qq.com/userinfo/realnameauth/query + *+ * + * @param request 请求对象 + * @return 实名认证查询结果 + * @throws WxPayException the wx pay exception + */ + RealNameResult queryRealName(RealNameRequest request) throws WxPayException; + + /** + *
+ * 获取用户实名认证信息API(简化方法). + * 用于商户查询用户的实名认证状态,如果用户未实名认证,会返回引导用户实名认证的URL + * 文档详见:https://pay.wechatpay.cn/doc/v2/merchant/4011987607 + * 接口链接:https://api.mch.weixin.qq.com/userinfo/realnameauth/query + *+ * + * @param openid 用户openid + * @return 实名认证查询结果 + * @throws WxPayException the wx pay exception + */ + RealNameResult queryRealName(String openid) throws WxPayException; +} diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/WxPayService.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/WxPayService.java index 93da0d133..52c3a506a 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/WxPayService.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/WxPayService.java @@ -1706,4 +1706,11 @@ public interface WxPayService { * @return the partner pay score sign plan service */ PartnerPayScoreSignPlanService getPartnerPayScoreSignPlanService(); + + /** + * 获取实名验证服务类 + * + * @return the real name service + */ + RealNameService getRealNameService(); } diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImpl.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImpl.java index ba3dc3714..0af5ee984 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImpl.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImpl.java @@ -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
+ * 微信支付实名验证相关服务实现类. + * 详见文档:https://pay.wechatpay.cn/doc/v2/merchant/4011987607 + *+ * + * @author Binary Wang + */ +@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); + } +}