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 map) { + map.put("openid", openid); + } +} diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/realname/RealNameResult.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/realname/RealNameResult.java new file mode 100644 index 000000000..0300cd88b --- /dev/null +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/realname/RealNameResult.java @@ -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; + +/** + *
+ * 微信支付实名验证返回结果.
+ * 详见文档: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 configMap = new ConcurrentHashMap<>(); @Override diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/RealNameServiceImpl.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/RealNameServiceImpl.java new file mode 100644 index 000000000..9a1c57fe0 --- /dev/null +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/RealNameServiceImpl.java @@ -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; + +/** + *
+ * 微信支付实名验证相关服务实现类.
+ * 详见文档: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); + } +}