View Javadoc
1   package com.foxinmy.weixin4j.pay.payment.mch;
2   
3   import com.alibaba.fastjson.JSON;
4   import com.alibaba.fastjson.annotation.JSONField;
5   
6   import javax.xml.bind.annotation.XmlAccessType;
7   import javax.xml.bind.annotation.XmlAccessorType;
8   import javax.xml.bind.annotation.XmlElement;
9   import javax.xml.bind.annotation.XmlRootElement;
10  
11  @XmlRootElement
12  @XmlAccessorType(XmlAccessType.FIELD)
13  public class SceneInfoApp implements SceneInfo {
14  	/**
15  	 * 终端类型
16  	 */
17  	private String type;
18  	/**
19  	 * WAP 网站名
20  	 */
21  	@XmlElement(name = "wap_name")
22  	@JSONField(name = "wap_name")
23  	private String name;
24  	/**
25  	 * WAP网站URL地址
26  	 */
27  	@XmlElement(name = "wap_url")
28  	@JSONField(name = "wap_url")
29  	private String path;
30  
31  	@JSONField(serialize = false)
32  	private String sceneInfo;
33  
34  	protected SceneInfoApp(){
35  
36  	}
37  
38  	private SceneInfoApp(String type, String name, String path) {
39  		this.type = type;
40  		this.name = name;
41  		this.path = path;
42  	}
43  
44  	public String getType() {
45  		return type;
46  	}
47  
48  	public void setType(String type) {
49  		this.type = type;
50  	}
51  
52  	public String getName() {
53  		return name;
54  	}
55  
56  	public void setName(String name) {
57  		this.name = name;
58  	}
59  
60  	public String getPath() {
61  		return path;
62  	}
63  
64  	public void setPath(String path) {
65  		this.path = path;
66  	}
67  
68  	@Deprecated
69  	public String getSceneInfo() {
70  		return sceneInfo;
71  	}
72  	@Deprecated
73  	public void setSceneInfo(String sceneInfo) {
74  		this.sceneInfo = sceneInfo;
75  	}
76  
77  	/**
78  	 * IOS应用
79  	 * APP环境直接使用APP支付,此方法将作废
80  	 * 
81  	 * @param appName 应用名
82  	 * @param bundleId 模块ID
83  	 * @return
84  	 * @deprecated
85  	 */
86  	@Deprecated
87  	public static SceneInfoApp createIOSAPP(String appName, String bundleId) {
88  		SceneInfoApp app = new SceneInfoApp("IOS", appName, bundleId);
89  		String sceneInfo = String
90  				.format("{\"type\": \"%s\",\"app_name\": \"%s\",\"bundle_id\": \"%s\"}",
91  						app.getType(), app.getName(), app.getPath());
92  		app.setSceneInfo(sceneInfo);
93  		return app;
94  	}
95  
96  	/**
97  	 * Android应用
98  	 * APP环境直接使用APP支付,此方法将作废
99  	 * 
100 	 * @param appName 应用名
101 	 * @param packageName 包名
102 	 * @return
103 	 * @deprecated
104 	 */
105 	@Deprecated
106 	public static SceneInfoApp createAndroidAPP(String appName, String packageName) {
107 		SceneInfoApp app = new SceneInfoApp("Android", appName, packageName);
108 		String sceneInfo = String
109 				.format("{\"type\": \"%s\",\"app_name\": \"%s\",\"package_name\": \"%s\"}",
110 						app.getType(), app.getName(), app.getPath());
111 		app.setSceneInfo(sceneInfo);
112 		return app;
113 	}
114 
115 	/**
116 	 * Wap应用
117 	 * 
118 	 * @param name
119 	 *            网站名
120 	 * @param url
121 	 *            网站URL地址
122 	 * @return
123 	 */
124 	public static SceneInfoApp createWapAPP(String name, String url) {
125 		SceneInfoApp app = new SceneInfoApp("Wap", name, url);
126 		String sceneInfo = String.format(
127 				"{\"type\": \"%s\",\"wap_name\": \"%s\",\"wap_url\": \"%s\"}",
128 				app.getType(), app.getName(), app.getPath());
129 		app.setSceneInfo(sceneInfo);
130 		return app;
131 	}
132 
133 	@Override
134 	public String toJson() {
135 		return String.format("{\"h5_info\": %s}", JSON.toJSONString(this));
136 	}
137 }