1 package com.foxinmy.weixin4j.pay.test;
2
3 import com.alibaba.fastjson.JSON;
4 import com.foxinmy.weixin4j.exception.WeixinException;
5 import com.foxinmy.weixin4j.pay.WeixinPayProxy;
6 import com.foxinmy.weixin4j.pay.model.WeixinPayAccount;
7 import com.foxinmy.weixin4j.pay.profitsharing.*;
8 import com.foxinmy.weixin4j.pay.type.profitsharing.ReceiverType;
9 import com.foxinmy.weixin4j.pay.type.profitsharing.RelationType;
10 import org.junit.Assert;
11 import org.junit.Test;
12
13 import java.util.ArrayList;
14 import java.util.List;
15
16 public class TestProfitSharingApi {
17
18 private static String APPID = "";
19
20 private static String PAY_SIGN_KEY = "";
21
22 private static String MCHID = "";
23
24 private static String OPENID = "";
25
26
27
28
29 @Test
30 public void testAddReceiver() throws WeixinException {
31 Receiver receiver = new Receiver(ReceiverType.PERSONAL_OPENID, OPENID, RelationType.STAFF);
32 WeixinPayAccount account = new WeixinPayAccount(APPID, PAY_SIGN_KEY, MCHID);
33 WeixinPayProxy proxy = new WeixinPayProxy(account);
34 ReceiverResult result = proxy.addProfitSharingReceiver(receiver);
35 System.out.println(JSON.toJSONString(result));
36 Assert.assertEquals(result.getReturnCode(), "SUCCESS");
37 }
38
39
40
41
42 @Test
43 public void testRemoveReceiver() throws WeixinException {
44 Receiver receiver = new Receiver(ReceiverType.PERSONAL_OPENID, OPENID, null);
45 WeixinPayAccount account = new WeixinPayAccount(APPID, PAY_SIGN_KEY, MCHID);
46 WeixinPayProxy proxy = new WeixinPayProxy(account);
47 ReceiverResult result = proxy.removeProfitSharingReceiver(receiver);
48 System.out.println(JSON.toJSONString(result));
49 Assert.assertEquals(result.getReturnCode(), "SUCCESS");
50 }
51
52
53
54
55
56
57 @Test
58 public void testProfitSharing() throws WeixinException {
59 ReceiverProfit receiverProfit = new ReceiverProfit(ReceiverType.MERCHANT_ID, "", 1, "test");
60 List<ReceiverProfit> list = new ArrayList<ReceiverProfit>();
61 list.add(receiverProfit);
62 WeixinPayAccount account = new WeixinPayAccount(APPID, PAY_SIGN_KEY, MCHID);
63 WeixinPayProxy proxy = new WeixinPayProxy(account);
64 ProfitSharingResult result = proxy.profitSharing("transactioId", "outOrderNo", list, false);
65 System.out.println(JSON.toJSONString(result));
66 Assert.assertEquals(result.getReturnCode(), "SUCCESS");
67 }
68
69 }