Skip to content

Commit 98cc008

Browse files
author
lucas
committed
Merge branch 'dev_2.9.0' into dev_lucas
2 parents 5eb848b + e1583c7 commit 98cc008

File tree

1 file changed

+96
-3
lines changed
  • VideoOS/VenvyLibrary/src/main/java/cn/com/venvy/common/webview

1 file changed

+96
-3
lines changed

VideoOS/VenvyLibrary/src/main/java/cn/com/venvy/common/webview/JsBridge.java

Lines changed: 96 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import cn.com.venvy.common.observer.VenvyObservable;
4141
import cn.com.venvy.common.observer.VenvyObservableTarget;
4242
import cn.com.venvy.common.observer.VenvyObserver;
43+
import cn.com.venvy.common.statistics.VenvyStatisticsManager;
4344
import cn.com.venvy.common.utils.VenvyAesUtil;
4445
import cn.com.venvy.common.utils.VenvyBase64;
4546
import cn.com.venvy.common.utils.VenvyDeviceUtil;
@@ -157,7 +158,14 @@ public void network(final String jsParams) {
157158
return;
158159
}
159160
try {
160-
JSONObject jsJsonObj = new JSONObject(jsParams);
161+
JSONObject msgJsonObj = new JSONObject(jsParams);
162+
if (msgJsonObj == null) {
163+
return;
164+
}
165+
JSONObject jsJsonObj = msgJsonObj.optJSONObject("msg");
166+
if (jsJsonObj == null) {
167+
return;
168+
}
161169
String url = jsJsonObj.optString("url");
162170
String method = jsJsonObj.optString("method");
163171
Map<String, String> param = VenvyMapUtil.jsonToMap(jsJsonObj.optString("param"));
@@ -178,15 +186,25 @@ public void network(final String jsParams) {
178186
public void requestFinish(Request request, IResponse response) {
179187
if (response.isSuccess()) {
180188
String result = response.getResult();
181-
callJsFunction(result, jsParams);
189+
try {
190+
JSONObject obj = new JSONObject(result);
191+
callJsFunction(obj.toString(), jsParams);
192+
} catch (Exception e) {
193+
e.printStackTrace();
194+
}
182195
} else {
183196
requestError(request, new Exception("http not successful"));
184197
}
185198
}
186199

187200
@Override
188201
public void requestError(Request request, @Nullable Exception e) {
189-
callJsFunction(e != null && e.getMessage() != null ? e.getMessage() : "unkown error", jsParams);
202+
try {
203+
JSONObject object = new JSONObject(e != null && e.getMessage() != null ? e.getMessage() : "unkown error");
204+
callJsFunction(object.toString(), jsParams);
205+
} catch (Exception exception) {
206+
exception.printStackTrace();
207+
}
190208
}
191209

192210
@Override
@@ -205,6 +223,81 @@ public void requestProgress(Request request, int progress) {
205223

206224
}
207225

226+
/***
227+
* 统计通用追踪
228+
* @param jsParams
229+
*/
230+
@JavascriptInterface
231+
public void commonTrack(final String jsParams) {
232+
if (TextUtils.isEmpty(jsParams)) {
233+
return;
234+
}
235+
try {
236+
JSONObject jsonObject = new JSONObject(jsParams);
237+
if (jsonObject == null) {
238+
return;
239+
}
240+
JSONObject msgObject = jsonObject.optJSONObject("msg");
241+
if (msgObject == null) {
242+
return;
243+
}
244+
Integer type = msgObject.optInt("type");
245+
String data = msgObject.optString("data");
246+
VenvyStatisticsManager.getInstance().submitCommonTrack(type, new JSONObject(data));
247+
} catch (Exception e) {
248+
e.printStackTrace();
249+
}
250+
}
251+
252+
/***
253+
* 打开广告
254+
* @param jsParams
255+
*/
256+
@JavascriptInterface
257+
public void openAds(String jsParams) {
258+
try {
259+
if(TextUtils.isEmpty(jsParams))
260+
return;
261+
JSONObject msgObject=
262+
JSONObject jsonObject = new JSONObject(jsParams);
263+
// VenvyLog.d("openAds : " + jsonObject.toString());
264+
if (jsonObject.has("targetType")) {
265+
String targetType = jsonObject.optString("targetType");
266+
JSONObject linkData = jsonObject.optJSONObject("linkData");
267+
String downAPI = jsonObject.optString("downloadApkUrl");
268+
String deepLink = linkData.optString("deepLink");
269+
// targetType 1 落地页 2 deepLink 3 下载
270+
if (targetType.equalsIgnoreCase("3")) {
271+
JSONObject downloadTrackLink = jsonObject.optJSONObject("downloadTrackLink");
272+
Bundle trackData = new Bundle();
273+
trackData.putString(VenvyObservableTarget.Constant.CONSTANT_DOWNLOAD_API, downAPI);
274+
trackData.putStringArray("isTrackLinks", JsonUtil.toStringArray(downloadTrackLink.optJSONArray("isTrackLinks")));
275+
trackData.putStringArray("dsTrackLinks", JsonUtil.toStringArray(downloadTrackLink.optJSONArray("dsTrackLinks")));
276+
trackData.putStringArray("dfTrackLinks", JsonUtil.toStringArray(downloadTrackLink.optJSONArray("dfTrackLinks")));
277+
trackData.putStringArray("instTrackLinks", JsonUtil.toStringArray(downloadTrackLink.optJSONArray("instTrackLinks")));
278+
trackData.putString("launchPlanId",jsonObject.optString("launchPlanId"));
279+
ObservableManager.getDefaultObserable().sendToTarget(VenvyObservableTarget.TAG_DOWNLOAD_TASK, trackData);
280+
} else {
281+
// 走Native:widgetNotify() 逻辑
282+
WidgetInfo.Builder builder = new WidgetInfo.Builder()
283+
.setWidgetActionType(WidgetInfo.WidgetActionType.ACTION_OPEN_URL)
284+
.setUrl("");
285+
if (targetType.equalsIgnoreCase("1")) {
286+
builder.setLinkUrl(downAPI);
287+
} else if (targetType.equalsIgnoreCase("2")) {
288+
builder.setDeepLink(deepLink);
289+
}
290+
WidgetInfo widgetInfo = builder.build();
291+
if (platform.getWidgetClickListener() != null) {
292+
platform.getWidgetClickListener().onClick(widgetInfo);
293+
}
294+
}
295+
}
296+
}catch (Exception e){
297+
e.printStackTrace();
298+
}
299+
}
300+
208301
@JavascriptInterface
209302
public void openUrl(String jsParams) {
210303
try {

0 commit comments

Comments
 (0)