RefundReqData.java 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. package com.tencent.protocol.refund_protocol;
  2. import com.tencent.common.Configure;
  3. import com.tencent.common.RandomStringGenerator;
  4. import com.tencent.common.Signature;
  5. import java.lang.reflect.Field;
  6. import java.util.HashMap;
  7. import java.util.Map;
  8. /**
  9. * User: rizenguo
  10. * Date: 2014/10/25
  11. * Time: 16:12
  12. */
  13. public class RefundReqData {
  14. //每个字段具体的意思请查看API文档
  15. private String appid = "";
  16. private String mch_id = "";
  17. private String device_info = "";
  18. private String nonce_str = "";
  19. private String sign = "";
  20. private String transaction_id = "";
  21. private String out_trade_no = "";
  22. private String out_refund_no = "";
  23. private int total_fee = 0;
  24. private int refund_fee = 0;
  25. private String refund_fee_type = "CNY";
  26. private String op_user_id = "";
  27. /**
  28. * 请求退款服务
  29. * @param transactionID 是微信系统为每一笔支付交易分配的订单号,通过这个订单号可以标识这笔交易,它由支付订单API支付成功时返回的数据里面获取到。建议优先使用
  30. * @param outTradeNo 商户系统内部的订单号,transaction_id 、out_trade_no 二选一,如果同时存在优先级:transaction_id>out_trade_no
  31. * @param deviceInfo 微信支付分配的终端设备号,与下单一致
  32. * @param outRefundNo 商户系统内部的退款单号,商户系统内部唯一,同一退款单号多次请求只退一笔
  33. * @param totalFee 订单总金额,单位为分
  34. * @param refundFee 退款总金额,单位为分,可以做部分退款
  35. * @param opUserID 操作员帐号, 默认为商户号
  36. * @param refundFeeType 货币类型,符合ISO 4217标准的三位字母代码,默认为CNY(人民币)
  37. */
  38. public RefundReqData(String transactionID,String outTradeNo,String deviceInfo,String outRefundNo,int totalFee,int refundFee,String opUserID,String refundFeeType){
  39. //微信分配的公众号ID(开通公众号之后可以获取到)
  40. setAppid(Configure.getAppid());
  41. //微信支付分配的商户号ID(开通公众号的微信支付功能之后可以获取到)
  42. setMch_id(Configure.getMchid());
  43. //transaction_id是微信系统为每一笔支付交易分配的订单号,通过这个订单号可以标识这笔交易,它由支付订单API支付成功时返回的数据里面获取到。
  44. setTransaction_id(transactionID);
  45. //商户系统自己生成的唯一的订单号
  46. setOut_trade_no(outTradeNo);
  47. //微信支付分配的终端设备号,与下单一致
  48. setDevice_info(deviceInfo);
  49. setOut_refund_no(outRefundNo);
  50. setTotal_fee(totalFee);
  51. setRefund_fee(refundFee);
  52. setOp_user_id(opUserID);
  53. //随机字符串,不长于32 位
  54. setNonce_str(RandomStringGenerator.getRandomStringByLength(32));
  55. //根据API给的签名规则进行签名
  56. String sign = Signature.getSign(toMap());
  57. setSign(sign);//把签名数据设置到Sign这个属性中
  58. }
  59. public String getAppid() {
  60. return appid;
  61. }
  62. public void setAppid(String appid) {
  63. this.appid = appid;
  64. }
  65. public String getMch_id() {
  66. return mch_id;
  67. }
  68. public void setMch_id(String mch_id) {
  69. this.mch_id = mch_id;
  70. }
  71. public String getDevice_info() {
  72. return device_info;
  73. }
  74. public void setDevice_info(String device_info) {
  75. this.device_info = device_info;
  76. }
  77. public String getNonce_str() {
  78. return nonce_str;
  79. }
  80. public void setNonce_str(String nonce_str) {
  81. this.nonce_str = nonce_str;
  82. }
  83. public String getSign() {
  84. return sign;
  85. }
  86. public void setSign(String sign) {
  87. this.sign = sign;
  88. }
  89. public String getTransaction_id() {
  90. return transaction_id;
  91. }
  92. public void setTransaction_id(String transaction_id) {
  93. this.transaction_id = transaction_id;
  94. }
  95. public String getOut_trade_no() {
  96. return out_trade_no;
  97. }
  98. public void setOut_trade_no(String out_trade_no) {
  99. this.out_trade_no = out_trade_no;
  100. }
  101. public String getOut_refund_no() {
  102. return out_refund_no;
  103. }
  104. public void setOut_refund_no(String out_refund_no) {
  105. this.out_refund_no = out_refund_no;
  106. }
  107. public int getTotal_fee() {
  108. return total_fee;
  109. }
  110. public void setTotal_fee(int total_fee) {
  111. this.total_fee = total_fee;
  112. }
  113. public int getRefund_fee() {
  114. return refund_fee;
  115. }
  116. public void setRefund_fee(int refund_fee) {
  117. this.refund_fee = refund_fee;
  118. }
  119. public String getOp_user_id() {
  120. return op_user_id;
  121. }
  122. public void setOp_user_id(String op_user_id) {
  123. this.op_user_id = op_user_id;
  124. }
  125. public String getRefund_fee_type() {
  126. return refund_fee_type;
  127. }
  128. public void setRefund_fee_type(String refund_fee_type) {
  129. this.refund_fee_type = refund_fee_type;
  130. }
  131. public Map<String,Object> toMap(){
  132. Map<String,Object> map = new HashMap<String, Object>();
  133. Field[] fields = this.getClass().getDeclaredFields();
  134. for (Field field : fields) {
  135. Object obj;
  136. try {
  137. obj = field.get(this);
  138. if(obj!=null){
  139. map.put(field.getName(), obj);
  140. }
  141. } catch (IllegalArgumentException e) {
  142. e.printStackTrace();
  143. } catch (IllegalAccessException e) {
  144. e.printStackTrace();
  145. }
  146. }
  147. return map;
  148. }
  149. }