fix javadoc

This commit is contained in:
Binary Wang 2018-03-28 19:20:43 +08:00
parent 2c2ed5d60c
commit e86adc1dc5
5 changed files with 113 additions and 102 deletions

View File

@ -12,7 +12,7 @@ import me.chanjar.weixin.common.util.http.RequestHttp;
*/ */
public interface WxMaService { public interface WxMaService {
/** /**
* 获取access_token * 获取access_token.
*/ */
String GET_ACCESS_TOKEN_URL = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s"; String GET_ACCESS_TOKEN_URL = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s";
@ -25,14 +25,14 @@ public interface WxMaService {
WxMaJscode2SessionResult jsCode2SessionInfo(String jsCode) throws WxErrorException; WxMaJscode2SessionResult jsCode2SessionInfo(String jsCode) throws WxErrorException;
/** /**
* <pre> * <pre>
* 验证消息的确来自微信服务器 * 验证消息的确来自微信服务器.
* 详情请见: http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421135319&token=&lang=zh_CN * 详情请见: http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421135319&token=&lang=zh_CN
* </pre> * </pre>
*/ */
boolean checkSignature(String timestamp, String nonce, String signature); boolean checkSignature(String timestamp, String nonce, String signature);
/** /**
* 获取access_token, 不强制刷新access_token * 获取access_token, 不强制刷新access_token.
* *
* @see #getAccessToken(boolean) * @see #getAccessToken(boolean)
*/ */
@ -40,7 +40,7 @@ public interface WxMaService {
/** /**
* <pre> * <pre>
* 获取access_token本方法线程安全 * 获取access_token本方法线程安全.
* 且在多线程同时刷新时只刷新一次避免超出2000次/日的调用次数上限 * 且在多线程同时刷新时只刷新一次避免超出2000次/日的调用次数上限
* *
* 本service的所有方法都会在access_token过期是调用此方法 * 本service的所有方法都会在access_token过期是调用此方法
@ -55,12 +55,12 @@ public interface WxMaService {
String getAccessToken(boolean forceRefresh) throws WxErrorException; String getAccessToken(boolean forceRefresh) throws WxErrorException;
/** /**
* 当本Service没有实现某个API的时候可以用这个针对所有微信API中的GET请求 * 当本Service没有实现某个API的时候可以用这个针对所有微信API中的GET请求.
*/ */
String get(String url, String queryParam) throws WxErrorException; String get(String url, String queryParam) throws WxErrorException;
/** /**
* 当本Service没有实现某个API的时候可以用这个针对所有微信API中的POST请求 * 当本Service没有实现某个API的时候可以用这个针对所有微信API中的POST请求.
*/ */
String post(String url, String postData) throws WxErrorException; String post(String url, String postData) throws WxErrorException;
@ -75,7 +75,7 @@ public interface WxMaService {
/** /**
* <pre> * <pre>
* 设置当微信系统响应系统繁忙时要等待多少 retrySleepMillis(ms) * 2^(重试次数 - 1) 再发起重试 * 设置当微信系统响应系统繁忙时要等待多少 retrySleepMillis(ms) * 2^(重试次数 - 1) 再发起重试.
* 默认1000ms * 默认1000ms
* </pre> * </pre>
*/ */
@ -83,65 +83,65 @@ public interface WxMaService {
/** /**
* <pre> * <pre>
* 设置当微信系统响应系统繁忙时最大重试次数 * 设置当微信系统响应系统繁忙时最大重试次数.
* 默认5次 * 默认5次
* </pre> * </pre>
*/ */
void setMaxRetryTimes(int maxRetryTimes); void setMaxRetryTimes(int maxRetryTimes);
/** /**
* 获取WxMaConfig 对象 * 获取WxMaConfig 对象.
* *
* @return WxMaConfig * @return WxMaConfig
*/ */
WxMaConfig getWxMaConfig(); WxMaConfig getWxMaConfig();
/** /**
* 注入 {@link WxMaConfig} 的实现 * 注入 {@link WxMaConfig} 的实现.
*/ */
void setWxMaConfig(WxMaConfig wxConfigProvider); void setWxMaConfig(WxMaConfig wxConfigProvider);
/** /**
* 返回消息客服消息和模版消息发送接口方法实现类以方便调用其各个接口 * 返回消息客服消息和模版消息发送接口方法实现类以方便调用其各个接口.
* *
* @return WxMaMsgService * @return WxMaMsgService
*/ */
WxMaMsgService getMsgService(); WxMaMsgService getMsgService();
/** /**
* 返回素材相关接口方法的实现类对象以方便调用其各个接口 * 返回素材相关接口方法的实现类对象以方便调用其各个接口.
* *
* @return WxMaMediaService * @return WxMaMediaService
*/ */
WxMaMediaService getMediaService(); WxMaMediaService getMediaService();
/** /**
* 返回用户相关接口方法的实现类对象以方便调用其各个接口 * 返回用户相关接口方法的实现类对象以方便调用其各个接口.
* *
* @return WxMaUserService * @return WxMaUserService
*/ */
WxMaUserService getUserService(); WxMaUserService getUserService();
/** /**
* 返回二维码相关接口方法的实现类对象以方便调用其各个接口 * 返回二维码相关接口方法的实现类对象以方便调用其各个接口.
* *
* @return WxMaQrcodeService * @return WxMaQrcodeService
*/ */
WxMaQrcodeService getQrcodeService(); WxMaQrcodeService getQrcodeService();
/** /**
* 返回模板配置相关接口方法的实现类对象, 以方便调用其各个接口 * 返回模板配置相关接口方法的实现类对象, 以方便调用其各个接口.
* @return WxMaTemplateService * @return WxMaTemplateService
*/ */
WxMaTemplateService getTemplateService(); WxMaTemplateService getTemplateService();
/** /**
* 初始化http请求对象 * 初始化http请求对象.
*/ */
void initHttp(); void initHttp();
/** /**
* 请求http请求相关信息 * 请求http请求相关信息.
*/ */
RequestHttp getRequestHttp(); RequestHttp getRequestHttp();

View File

@ -5,21 +5,21 @@ import cn.binarywang.wx.miniapp.bean.WxMaUserInfo;
import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.common.exception.WxErrorException;
/** /**
* 用户信息相关操作接口 * 用户信息相关操作接口.
* *
* @author <a href="https://github.com/binarywang">Binary Wang</a> * @author <a href="https://github.com/binarywang">Binary Wang</a>
*/ */
public interface WxMaUserService { public interface WxMaUserService {
/** /**
* 获取登录后的session信息 * 获取登录后的session信息.
* *
* @param jsCode 登录时获取的 code * @param jsCode 登录时获取的 code
*/ */
WxMaJscode2SessionResult getSessionInfo(String jsCode) throws WxErrorException; WxMaJscode2SessionResult getSessionInfo(String jsCode) throws WxErrorException;
/** /**
* 解密用户敏感数据 * 解密用户敏感数据.
* *
* @param sessionKey 会话密钥 * @param sessionKey 会话密钥
* @param encryptedData 消息密文 * @param encryptedData 消息密文
@ -28,7 +28,7 @@ public interface WxMaUserService {
WxMaUserInfo getUserInfo(String sessionKey, String encryptedData, String ivStr); WxMaUserInfo getUserInfo(String sessionKey, String encryptedData, String ivStr);
/** /**
* 验证用户信息完整性 * 验证用户信息完整性.
* *
* @param sessionKey 会话密钥 * @param sessionKey 会话密钥
* @param rawData 微信用户基本信息 * @param rawData 微信用户基本信息

View File

@ -1,18 +1,10 @@
package cn.binarywang.wx.miniapp.api.impl; package cn.binarywang.wx.miniapp.api.impl;
import cn.binarywang.wx.miniapp.api.*; import java.io.IOException;
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult; import java.util.HashMap;
import cn.binarywang.wx.miniapp.config.WxMaConfig; import java.util.Map;
import cn.binarywang.wx.miniapp.constant.WxMaConstants; import java.util.concurrent.locks.Lock;
import com.google.common.base.Joiner;
import com.google.gson.JsonParser;
import me.chanjar.weixin.common.bean.WxAccessToken;
import me.chanjar.weixin.common.bean.result.WxError;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.common.util.crypto.SHA1;
import me.chanjar.weixin.common.util.http.*;
import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
import me.chanjar.weixin.common.util.http.apache.DefaultApacheHttpClientBuilder;
import org.apache.http.HttpHost; import org.apache.http.HttpHost;
import org.apache.http.client.config.RequestConfig; import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.CloseableHttpResponse;
@ -22,16 +14,32 @@ import org.apache.http.impl.client.CloseableHttpClient;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.IOException; import cn.binarywang.wx.miniapp.api.WxMaMediaService;
import java.util.HashMap; import cn.binarywang.wx.miniapp.api.WxMaMsgService;
import java.util.Map; import cn.binarywang.wx.miniapp.api.WxMaQrcodeService;
import java.util.concurrent.locks.Lock; import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.WxMaTemplateService;
import cn.binarywang.wx.miniapp.api.WxMaUserService;
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
import cn.binarywang.wx.miniapp.config.WxMaConfig;
import cn.binarywang.wx.miniapp.constant.WxMaConstants;
import com.google.common.base.Joiner;
import me.chanjar.weixin.common.bean.WxAccessToken;
import me.chanjar.weixin.common.bean.result.WxError;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.common.util.crypto.SHA1;
import me.chanjar.weixin.common.util.http.HttpType;
import me.chanjar.weixin.common.util.http.RequestExecutor;
import me.chanjar.weixin.common.util.http.RequestHttp;
import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor;
import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor;
import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
import me.chanjar.weixin.common.util.http.apache.DefaultApacheHttpClientBuilder;
/** /**
* @author <a href="https://github.com/binarywang">Binary Wang</a> * @author <a href="https://github.com/binarywang">Binary Wang</a>
*/ */
public class WxMaServiceImpl implements WxMaService, RequestHttp<CloseableHttpClient, HttpHost> { public class WxMaServiceImpl implements WxMaService, RequestHttp<CloseableHttpClient, HttpHost> {
private static final JsonParser JSON_PARSER = new JsonParser();
private final Logger log = LoggerFactory.getLogger(this.getClass()); private final Logger log = LoggerFactory.getLogger(this.getClass());
private CloseableHttpClient httpClient; private CloseableHttpClient httpClient;
@ -137,6 +145,7 @@ public class WxMaServiceImpl implements WxMaService, RequestHttp<CloseableHttpCl
String result = get(JSCODE_TO_SESSION_URL, Joiner.on("&").withKeyValueSeparator("=").join(params)); String result = get(JSCODE_TO_SESSION_URL, Joiner.on("&").withKeyValueSeparator("=").join(params));
return WxMaJscode2SessionResult.fromJson(result); return WxMaJscode2SessionResult.fromJson(result);
} }
@Override @Override
public boolean checkSignature(String timestamp, String nonce, String signature) { public boolean checkSignature(String timestamp, String nonce, String signature) {
try { try {

View File

@ -1,5 +1,10 @@
package cn.binarywang.wx.miniapp.api.impl; package cn.binarywang.wx.miniapp.api.impl;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.codec.digest.DigestUtils;
import cn.binarywang.wx.miniapp.api.WxMaService; import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.WxMaUserService; import cn.binarywang.wx.miniapp.api.WxMaUserService;
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult; import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
@ -8,10 +13,6 @@ import cn.binarywang.wx.miniapp.config.WxMaConfig;
import cn.binarywang.wx.miniapp.util.crypt.WxMaCryptUtils; import cn.binarywang.wx.miniapp.util.crypt.WxMaCryptUtils;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.common.exception.WxErrorException;
import org.apache.commons.codec.digest.DigestUtils;
import java.util.HashMap;
import java.util.Map;
/** /**
* @author <a href="https://github.com/binarywang">Binary Wang</a> * @author <a href="https://github.com/binarywang">Binary Wang</a>

View File

@ -1,12 +1,11 @@
package com.github.binarywang.wxpay.constant; package com.github.binarywang.wxpay.constant;
import com.google.common.collect.Lists; import java.text.Format;
import java.util.List;
import org.apache.commons.lang3.time.FastDateFormat; import org.apache.commons.lang3.time.FastDateFormat;
import java.text.DateFormat; import com.google.common.collect.Lists;
import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.List;
/** /**
* <pre> * <pre>
@ -19,95 +18,96 @@ import java.util.List;
public class WxPayConstants { public class WxPayConstants {
/** /**
* 拉取订单评价数据接口的参数中日期格式 * 拉取订单评价数据接口的参数中日期格式.
*/ */
public static final Format QUERY_COMMENT_DATE_FORMAT = FastDateFormat.getInstance("yyyyMMddHHmmss"); public static final Format QUERY_COMMENT_DATE_FORMAT = FastDateFormat.getInstance("yyyyMMddHHmmss");
/** /**
* 校验用户姓名选项企业付款时使用 * 校验用户姓名选项企业付款时使用.
*/ */
public static class CheckNameOption { public static class CheckNameOption {
/** /**
* 不校验真实姓名 * 不校验真实姓名.
*/ */
public static final String NO_CHECK = "NO_CHECK"; public static final String NO_CHECK = "NO_CHECK";
/** /**
* 强校验真实姓名 * 强校验真实姓名.
*/ */
public static final String FORCE_CHECK = "FORCE_CHECK"; public static final String FORCE_CHECK = "FORCE_CHECK";
} }
/** /**
* 压缩账单的类型 * 压缩账单的类型.
*/ */
public static class TarType { public static class TarType {
/** /**
* 固定值GZIP返回格式为.gzip的压缩包账单 * 固定值GZIP返回格式为.gzip的压缩包账单.
*/ */
public static final String GZIP = "GZIP"; public static final String GZIP = "GZIP";
} }
/** /**
* 账单类型 * 账单类型.
*/ */
public static class BillType { public static class BillType {
/** /**
* 查询红包时使用通过商户订单号获取红包信息 * 查询红包时使用通过商户订单号获取红包信息.
*/ */
public static final String MCHT = "MCHT"; public static final String MCHT = "MCHT";
//以下为下载对账单时的账单类型 //以下为下载对账单时的账单类型
/** /**
* 返回当日所有订单信息默认值 * 返回当日所有订单信息默认值.
*/ */
public static final String ALL = "ALL"; public static final String ALL = "ALL";
/** /**
* 返回当日成功支付的订单 * 返回当日成功支付的订单.
*/ */
public static final String SUCCESS = "SUCCESS"; public static final String SUCCESS = "SUCCESS";
/** /**
* 返回当日退款订单 * 返回当日退款订单.
*/ */
public static final String REFUND = "REFUND"; public static final String REFUND = "REFUND";
/** /**
* 返回当日充值退款订单相比其他对账单多一栏返还手续费 * 返回当日充值退款订单相比其他对账单多一栏返还手续费.
*/ */
public static final String RECHARGE_REFUND = "RECHARGE_REFUND"; public static final String RECHARGE_REFUND = "RECHARGE_REFUND";
} }
/** /**
* 交易类型 * 交易类型.
*/ */
public static class TradeType { public static class TradeType {
/** /**
* 原生扫码支付 * 原生扫码支付.
*/ */
public static final String NATIVE = "NATIVE"; public static final String NATIVE = "NATIVE";
/** /**
* App支付 * App支付.
*/ */
public static final String APP = "APP"; public static final String APP = "APP";
/** /**
* 公众号支付 * 公众号支付.
*/ */
public static final String JSAPI = "JSAPI"; public static final String JSAPI = "JSAPI";
/** /**
* H5支付 * H5支付.
*/ */
public static final String MWEB = "MWEB"; public static final String MWEB = "MWEB";
/** /**
* 刷卡支付刷卡支付有单独的支付接口不调用统一下单接口 * 刷卡支付.
* 刷卡支付有单独的支付接口不调用统一下单接口
*/ */
public static final String MICROPAY = "MICROPAY"; public static final String MICROPAY = "MICROPAY";
} }
/** /**
* 签名类型 * 签名类型.
*/ */
public static class SignType { public static class SignType {
public static final String HMAC_SHA256 = "HMAC-SHA256"; public static final String HMAC_SHA256 = "HMAC-SHA256";
@ -116,177 +116,178 @@ public class WxPayConstants {
} }
/** /**
* 限定支付方式 * 限定支付方式.
*/ */
public static class LimitPay { public static class LimitPay {
/** /**
* no_credit--指定不能使用信用卡支付 * no_credit--指定不能使用信用卡支付.
*/ */
public static final String NO_CREDIT = "no_credit"; public static final String NO_CREDIT = "no_credit";
} }
/** /**
* 业务结果代码 * 业务结果代码.
*/ */
public static class ResultCode { public static class ResultCode {
/** /**
* 成功 * 成功.
*/ */
public static final String SUCCESS = "SUCCESS"; public static final String SUCCESS = "SUCCESS";
/** /**
* 失败 * 失败.
*/ */
public static final String FAIL = "FAIL"; public static final String FAIL = "FAIL";
} }
/** /**
* 退款资金来源 * 退款资金来源.
*/ */
public static class RefundAccountSource { public static class RefundAccountSource {
/** /**
* 可用余额退款/基本账户 * 可用余额退款/基本账户.
*/ */
public static final String RECHARGE_FUNDS = "REFUND_SOURCE_RECHARGE_FUNDS"; public static final String RECHARGE_FUNDS = "REFUND_SOURCE_RECHARGE_FUNDS";
/** /**
* 未结算资金退款 * 未结算资金退款.
*/ */
public static final String UNSETTLED_FUNDS = "REFUND_SOURCE_UNSETTLED_FUNDS"; public static final String UNSETTLED_FUNDS = "REFUND_SOURCE_UNSETTLED_FUNDS";
} }
/** /**
* 退款渠道 * 退款渠道.
*/ */
public static class RefundChannel { public static class RefundChannel {
/** /**
* 原路退款 * 原路退款.
*/ */
public static final String ORIGINAL = "ORIGINAL"; public static final String ORIGINAL = "ORIGINAL";
/** /**
* 退回到余额 * 退回到余额.
*/ */
public static final String BALANCE = "BALANCE"; public static final String BALANCE = "BALANCE";
/** /**
* 原账户异常退到其他余额账户 * 原账户异常退到其他余额账户.
*/ */
public static final String OTHER_BALANCE = "OTHER_BALANCE"; public static final String OTHER_BALANCE = "OTHER_BALANCE";
/** /**
* 原银行卡异常退到其他银行卡 * 原银行卡异常退到其他银行卡.
*/ */
public static final String OTHER_BANKCARD = "OTHER_BANKCARD"; public static final String OTHER_BANKCARD = "OTHER_BANKCARD";
} }
/** /**
* 交易状态 * 交易状态.
*/ */
public static class WxpayTradeStatus { public static class WxpayTradeStatus {
/** /**
* 支付成功 * 支付成功.
*/ */
public static final String SUCCESS = "SUCCESS"; public static final String SUCCESS = "SUCCESS";
/** /**
* 支付失败(其他原因如银行返回失败) * 支付失败(其他原因如银行返回失败).
*/ */
public static final String PAY_ERROR = "PAYERROR"; public static final String PAY_ERROR = "PAYERROR";
/** /**
* 用户支付中 * 用户支付中.
*/ */
public static final String USER_PAYING = "USERPAYING"; public static final String USER_PAYING = "USERPAYING";
/** /**
* 已关闭 * 已关闭.
*/ */
public static final String CLOSED = "CLOSED"; public static final String CLOSED = "CLOSED";
/** /**
* 未支付 * 未支付.
*/ */
public static final String NOTPAY = "NOTPAY"; public static final String NOTPAY = "NOTPAY";
/** /**
* 转入退款 * 转入退款.
*/ */
public static final String REFUND = "REFUND"; public static final String REFUND = "REFUND";
/** /**
* 已撤销刷卡支付 * 已撤销刷卡支付.
*/ */
public static final String REVOKED = "REVOKED"; public static final String REVOKED = "REVOKED";
} }
/** /**
* 退款状态 * 退款状态.
*/ */
public static class RefundStatus { public static class RefundStatus {
/** /**
* 退款成功 * 退款成功.
*/ */
public static final String SUCCESS = "SUCCESS"; public static final String SUCCESS = "SUCCESS";
/** /**
* 退款关闭 * 退款关闭.
*/ */
public static final String REFUND_CLOSE = "REFUNDCLOSE"; public static final String REFUND_CLOSE = "REFUNDCLOSE";
/** /**
* 退款处理中 * 退款处理中.
*/ */
public static final String PROCESSING = "PROCESSING"; public static final String PROCESSING = "PROCESSING";
/** /**
* 退款异常退款到银行发现用户的卡作废或者冻结了导致原路退款银行卡失败可前往商户平台pay.weixin.qq.com-交易中心手动处理此笔退款 * 退款异常.
* 退款到银行发现用户的卡作废或者冻结了导致原路退款银行卡失败可前往商户平台pay.weixin.qq.com-交易中心手动处理此笔退款
*/ */
public static final String CHANGE = "CHANGE"; public static final String CHANGE = "CHANGE";
} }
/** /**
* 关闭订单结果错误代码 * 关闭订单结果错误代码.
*/ */
public static class OrderCloseResultErrorCode { public static class OrderCloseResultErrorCode {
/** /**
* 订单已支付 * 订单已支付.
*/ */
public static final String ORDER_PAID = "ORDERPAID"; public static final String ORDER_PAID = "ORDERPAID";
/** /**
* 系统错误 * 系统错误.
*/ */
public static final String SYSTEM_ERROR = "SYSTEMERROR"; public static final String SYSTEM_ERROR = "SYSTEMERROR";
/** /**
* 订单不存在 * 订单不存在.
*/ */
public static final String ORDER_NOT_EXIST = "ORDERNOTEXIST"; public static final String ORDER_NOT_EXIST = "ORDERNOTEXIST";
/** /**
* 订单已关闭 * 订单已关闭.
*/ */
public static final String ORDER_CLOSED = "ORDERCLOSED"; public static final String ORDER_CLOSED = "ORDERCLOSED";
/** /**
* 签名错误 * 签名错误.
*/ */
public static final String SIGN_ERROR = "SIGNERROR"; public static final String SIGN_ERROR = "SIGNERROR";
/** /**
* 未使用POST传递参数 * 未使用POST传递参数.
*/ */
public static final String REQUIRE_POST_METHOD = "REQUIRE_POST_METHOD"; public static final String REQUIRE_POST_METHOD = "REQUIRE_POST_METHOD";
/** /**
* XML格式错误 * XML格式错误.
*/ */
public static final String XML_FORMAT_ERROR = "XML_FORMAT_ERROR"; public static final String XML_FORMAT_ERROR = "XML_FORMAT_ERROR";
/** /**
* 订单状态错误 * 订单状态错误.
*/ */
public static final String TRADE_STATE_ERROR = "TRADE_STATE_ERROR"; public static final String TRADE_STATE_ERROR = "TRADE_STATE_ERROR";
} }