View Javadoc
1   package com.foxinmy.weixin4j.api;
2   
3   import com.alibaba.fastjson.JSON;
4   import com.alibaba.fastjson.JSONObject;
5   import com.alibaba.fastjson.TypeReference;
6   import com.foxinmy.weixin4j.exception.WeixinException;
7   import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
8   import com.foxinmy.weixin4j.model.WeixinPayAccount;
9   import com.foxinmy.weixin4j.payment.mch.CustomsOrder;
10  import com.foxinmy.weixin4j.payment.mch.CustomsOrderRecord;
11  import com.foxinmy.weixin4j.payment.mch.CustomsOrderResult;
12  import com.foxinmy.weixin4j.type.CustomsCity;
13  import com.foxinmy.weixin4j.type.IdQuery;
14  import com.foxinmy.weixin4j.xml.ListsuffixResultDeserializer;
15  import com.foxinmy.weixin4j.xml.XmlStream;
16  
17  /**
18   * 报关接口
19   *
20   * @className CustomsApi
21   * @author jinyu(foxinmy@gmail.com)
22   * @date 2016年3月67日
23   * @since JDK 1.6
24   * @see
25   * @deprecated 商户平台API迁移到子模块weixin4j-pay
26   */
27  @Deprecated
28  public class CustomsApi extends MchApi {
29  
30  	public CustomsApi(WeixinPayAccount weixinAccount) {
31  		super(weixinAccount);
32  	}
33  
34  	/**
35  	 * 订单附加信息提交
36  	 *
37  	 * @param customsOrder
38  	 *            附加订单信息
39  	 * @return 报关结果
40  	 * @see com.foxinmy.weixin4j.payment.mch.CustomsOrder
41  	 * @see com.foxinmy.weixin4j.payment.mch.CustomsOrderResult
42  	 * @see <a
43  	 *      href="https://pay.weixin.qq.com/wiki/doc/api/external/declarecustom.php?chapter=18_1">附加订单信息提交接口</a>
44  	 * @throws WeixinException
45  	 */
46  	public CustomsOrderResult declareCustomsOrder(CustomsOrder customsOrder)
47  			throws WeixinException {
48  		JSONObject para = (JSONObject) JSON.toJSON(customsOrder);
49  		para.put("appid", weixinAccount.getId());
50  		para.put("mch_id", weixinAccount.getMchId());
51  		para.put("sign", weixinSignature.sign(para));
52  		String param = XmlStream.map2xml(para);
53  		WeixinResponse response = weixinExecutor.post(
54  				getRequestUri("customsorder_declare_uri"), param);
55  		return response.getAsObject(new TypeReference<CustomsOrderResult>() {
56  		});
57  	}
58  
59  	/**
60  	 * 订单附加信息查询
61  	 *
62  	 * @param idQuery
63  	 *            out_trade_no,transaction_id,sub_order_no,sub_order_id四选一
64  	 * @param customsCity
65  	 *            海关
66  	 * @return 报关记录
67  	 * @see com.foxinmy.weixin4j.payment.mch.CustomsOrderRecord
68  	 * @see <a
69  	 *      href="https://pay.weixin.qq.com/wiki/doc/api/external/declarecustom.php?chapter=18_1">附加订单信息查询接口</a>
70  	 * @throws WeixinException
71  	 */
72  	public CustomsOrderRecord queryCustomsOrder(IdQuery idQuery,
73  			CustomsCity customsCity) throws WeixinException {
74  		JSONObject para = new JSONObject();
75  		para.put("appid", weixinAccount.getId());
76  		para.put("mch_id", weixinAccount.getMchId());
77  		para.put(idQuery.getType().getName(), idQuery.getId());
78  		para.put("customs", customsCity.name());
79  		para.put("sign", weixinSignature.sign(para));
80  		String param = XmlStream.map2xml(para);
81  		WeixinResponse response = weixinExecutor.post(
82  				getRequestUri("customsorder_query_uri"), param);
83  		return ListsuffixResultDeserializer.deserialize(response.getAsString(),
84  				CustomsOrderRecord.class);
85  	}
86  }