ReverseReqData.java 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. package com.tencent.protocol.reverse_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:42
  12. */
  13. public class ReverseReqData {
  14. //每个字段具体的意思请查看API文档
  15. private String appid = "";
  16. private String mch_id = "";
  17. private String transaction_id = "";
  18. private String out_trade_no = "";
  19. private String nonce_str = "";
  20. private String sign = "";
  21. /**
  22. * 请求撤销服务
  23. * @param transactionID 是微信系统为每一笔支付交易分配的订单号,通过这个订单号可以标识这笔交易,它由支付订单API支付成功时返回的数据里面获取到。建议优先使用
  24. * @param outTradeNo 商户系统内部的订单号,transaction_id 、out_trade_no 二选一,如果同时存在优先级:transaction_id>out_trade_no
  25. * @return API返回的XML数据
  26. * @throws Exception
  27. */
  28. public ReverseReqData(String transactionID,String outTradeNo){
  29. //--------------------------------------------------------------------
  30. //以下是测试数据,请商户按照自己的实际情况填写具体的值进去
  31. //--------------------------------------------------------------------
  32. //微信分配的公众号ID(开通公众号之后可以获取到)
  33. setAppid(Configure.getAppid());
  34. //微信支付分配的商户号ID(开通公众号的微信支付功能之后可以获取到)
  35. setMch_id(Configure.getMchid());
  36. //transaction_id是微信系统为每一笔支付交易分配的订单号,通过这个订单号可以标识这笔交易,它由支付订单API支付成功时返回的数据里面获取到。
  37. setTransaction_id(transactionID);
  38. //商户系统自己生成的唯一的订单号
  39. setOut_trade_no(outTradeNo);
  40. //随机字符串,不长于32 位
  41. setNonce_str(RandomStringGenerator.getRandomStringByLength(32));
  42. //根据API给的签名规则进行签名
  43. String sign = Signature.getSign(toMap());
  44. setSign(sign);//把签名数据设置到Sign这个属性中
  45. }
  46. public String getAppid() {
  47. return appid;
  48. }
  49. public void setAppid(String appid) {
  50. this.appid = appid;
  51. }
  52. public String getMch_id() {
  53. return mch_id;
  54. }
  55. public void setMch_id(String mch_id) {
  56. this.mch_id = mch_id;
  57. }
  58. public String getTransaction_id() {
  59. return transaction_id;
  60. }
  61. public void setTransaction_id(String transaction_id) {
  62. this.transaction_id = transaction_id;
  63. }
  64. public String getOut_trade_no() {
  65. return out_trade_no;
  66. }
  67. public void setOut_trade_no(String out_trade_no) {
  68. this.out_trade_no = out_trade_no;
  69. }
  70. public String getNonce_str() {
  71. return nonce_str;
  72. }
  73. public void setNonce_str(String nonce_str) {
  74. this.nonce_str = nonce_str;
  75. }
  76. public String getSign() {
  77. return sign;
  78. }
  79. public void setSign(String sign) {
  80. this.sign = sign;
  81. }
  82. public Map<String,Object> toMap(){
  83. Map<String,Object> map = new HashMap<String, Object>();
  84. Field[] fields = this.getClass().getDeclaredFields();
  85. for (Field field : fields) {
  86. Object obj;
  87. try {
  88. obj = field.get(this);
  89. if(obj!=null){
  90. map.put(field.getName(), obj);
  91. }
  92. } catch (IllegalArgumentException e) {
  93. e.printStackTrace();
  94. } catch (IllegalAccessException e) {
  95. e.printStackTrace();
  96. }
  97. }
  98. return map;
  99. }
  100. }