2424import cn .com .venvy .CommonParam ;
2525import cn .com .venvy .Platform ;
2626import cn .com .venvy .common .bean .PlatformUserInfo ;
27+ import cn .com .venvy .common .bean .WidgetInfo ;
2728import cn .com .venvy .common .exception .LoginException ;
2829import cn .com .venvy .common .interf .ICallJsFunction ;
2930import cn .com .venvy .common .interf .IPlatformLoginInterface ;
3435import cn .com .venvy .common .utils .VenvyBase64 ;
3536import cn .com .venvy .common .utils .VenvyDeviceUtil ;
3637import cn .com .venvy .common .utils .VenvyLog ;
38+ import cn .com .venvy .common .utils .VenvyMD5Util ;
3739import cn .com .venvy .common .utils .VenvyUIUtil ;
3840
3941import static cn .com .venvy .common .observer .VenvyObservableTarget .TAG_JS_BRIDGE_OBSERVER ;
@@ -55,6 +57,7 @@ public class JsBridge implements VenvyObserver {
5557 private Platform mPlatform ;
5658 // private JsParamsInfo mParamsInfo;
5759 public String mJsData ;
60+ public String mJsTitle ;
5861
5962 public JsBridge (Context context , @ NonNull IVenvyWebView webView , Platform platform ) {
6063 this .mVenvyWebView = webView ;
@@ -70,6 +73,11 @@ public void setJsData(String jsData) {
7073 this .mJsData = jsData ;
7174 }
7275
76+ public void setJsData (String jsData , String jsTitle ) {
77+ this .mJsData = jsData ;
78+ this .mJsTitle = jsTitle ;
79+ }
80+
7381 public void setCallJsFunction (ICallJsFunction jsFunction ) {
7482 mCallJsFunction = jsFunction ;
7583 }
@@ -95,13 +103,61 @@ public void commonData(String jsParams) {
95103 objSize .put ("height" , height );
96104 obj .put ("common" , CommonParam .getCommonParamJson (mPlatform .getPlatformInfo ().getAppKey ()));
97105 obj .put ("size" , objSize );
98- obj .put ("secret" ,mPlatform .getPlatformInfo ().getAppSecret ());
106+ obj .put ("secret" , mPlatform .getPlatformInfo ().getAppSecret ());
99107 } catch (Exception e ) {
100108
101109 }
102110 callJsFunction (obj .toString (), jsParams );
103111 }
104112
113+ @ JavascriptInterface
114+ public void openUrl (String jsParams ) {
115+ try {
116+ JSONObject obj = new JSONObject (jsParams );
117+ JSONObject msgObj = obj .optJSONObject ("msg" );
118+ String linkUrl = msgObj .optString ("linkUrl" );
119+ String deepLink = msgObj .optString ("deepLink" );
120+ String selfLink = msgObj .optString ("selfLink" );
121+ String actionString = "" ;
122+ if (!TextUtils .isEmpty (linkUrl )) {
123+ actionString = linkUrl ;
124+ } else if (TextUtils .isEmpty (deepLink )) {
125+ actionString = deepLink ;
126+ } else if (TextUtils .isEmpty (selfLink )) {
127+ actionString = selfLink ;
128+ }
129+ String adID = VenvyMD5Util .MD5 (actionString );
130+ WidgetInfo .WidgetActionType widgetActionType = WidgetInfo .WidgetActionType .findTypeById (1 );
131+ WidgetInfo widgetInfo = new WidgetInfo .Builder ()
132+ .setAdId (adID )
133+ .setWidgetActionType (widgetActionType )
134+ .setUrl (actionString )
135+ .setWidgetName (TextUtils .isEmpty (mJsTitle ) ? "" : mJsTitle )
136+ .setDeepLink (deepLink )
137+ .setLinkUrl (linkUrl )
138+ .setSelfLink (selfLink )
139+ .build ();
140+ if (mPlatform .getWidgetClickListener () != null && adID != null ) {
141+ mPlatform .getWidgetClickListener ().onClick (widgetInfo );
142+ }
143+ boolean canOpen = isPayInstall (Uri .parse (deepLink ));
144+ JSONObject jsonObject = new JSONObject ();
145+ if (TextUtils .isEmpty (deepLink )) {
146+ jsonObject .put ("canOpen" , 0 );
147+ } else {
148+ if (canOpen ) {
149+ jsonObject .put ("canOpen" , 1 );
150+ } else {
151+ jsonObject .put ("canOpen" , 2 );
152+ }
153+ }
154+ callJsFunction (jsonObject .toString (), jsParams );
155+
156+ } catch (Exception e ) {
157+ e .printStackTrace ();
158+ }
159+ }
160+
105161 @ JavascriptInterface
106162 public void getInitData (String jsParams ) {
107163 if (TextUtils .isEmpty (mJsData )) {
0 commit comments