修改了埋点SDK和福建移动获取视频播放链接
Showing
7 changed files
with
371 additions
and
93 deletions
| ... | @@ -183,7 +183,12 @@ cc.Class({ | ... | @@ -183,7 +183,12 @@ cc.Class({ |
| 183 | 183 | ||
| 184 | this.checkCollect(); | 184 | this.checkCollect(); |
| 185 | this.getGatherDetailList(); //获取剧集列表 | 185 | this.getGatherDetailList(); //获取剧集列表 |
| 186 | this.getPlayURLAndPlay(); | 186 | |
| 187 | // this.getPlayURLAndPlay();//先改为从java获取 | ||
| 188 | if (cc.sys.isNative) { | ||
| 189 | jsb.reflection.callStaticMethod("org/cocos2dx/javascript/common/TopdrawSDKWrapper", "getPlayUrl", "(Ljava/lang/String;)V", "getPlayURLAndPlay"); | ||
| 190 | } | ||
| 191 | |||
| 187 | } else { | 192 | } else { |
| 188 | cc.log("Business Error:Get checkPfbReadyAndInitPage..." + oJSONResult.description); | 193 | cc.log("Business Error:Get checkPfbReadyAndInitPage..." + oJSONResult.description); |
| 189 | } | 194 | } |
| ... | @@ -215,12 +220,14 @@ cc.Class({ | ... | @@ -215,12 +220,14 @@ cc.Class({ |
| 215 | } | 220 | } |
| 216 | }, | 221 | }, |
| 217 | 222 | ||
| 218 | getPlayURLAndPlay: function () { | 223 | getPlayURLAndPlay: function (playUrl) { |
| 219 | try { | 224 | try { |
| 225 | cc.log("videoDetail.js -> getPlayURLAndPlay | "+playUrl); | ||
| 220 | this._ComOperation.initPlayer(64, 56, 564, 317, true, true); //这里采用左右边距对应android坐标 fix jerry | 226 | this._ComOperation.initPlayer(64, 56, 564, 317, true, true); //这里采用左右边距对应android坐标 fix jerry |
| 221 | // this._ComOperation.initPlayer(0, 0, Common.SCREEN_WIDTH, Common.SCREEN_HEIGHT, true, true); //测试 | 227 | // this._ComOperation.initPlayer(0, 0, Common.SCREEN_WIDTH, Common.SCREEN_HEIGHT, true, true); //测试 |
| 222 | let options = {}; | 228 | let options = {}; |
| 223 | options.playurl = this._oInit.url; | 229 | // options.playurl = this._oInit.url; |
| 230 | options.playurl = playUrl; | ||
| 224 | this._ComOperation.setURL(options); //测试播放地址 | 231 | this._ComOperation.setURL(options); //测试播放地址 |
| 225 | } catch (error) { | 232 | } catch (error) { |
| 226 | if (cc.sys.isNative) { | 233 | if (cc.sys.isNative) { | ... | ... |
| ... | @@ -325,6 +325,7 @@ | ... | @@ -325,6 +325,7 @@ |
| 325 | "name": "记忆翻牌", | 325 | "name": "记忆翻牌", |
| 326 | "imageURL": "upload/image/main/记忆翻牌172-228.png", | 326 | "imageURL": "upload/image/main/记忆翻牌172-228.png", |
| 327 | "title_visible": 1, | 327 | "title_visible": 1, |
| 328 | "tvlink2": "{\"click\":[{\"action\":\"ChangeScene\",\"parameters\":{\"sceneName\":\"sceneGameDetail\",\"packageName\":\"com.orbbec.basketball\"}}]}", | ||
| 328 | "tvlink": "{\"click\":[{\"action\":\"ChangeScene\",\"parameters\":{\"sceneName\":\"sceneGameDetail\",\"packageName\":\"com.topdraw.xhx.fanpai\"}}]}", | 329 | "tvlink": "{\"click\":[{\"action\":\"ChangeScene\",\"parameters\":{\"sceneName\":\"sceneGameDetail\",\"packageName\":\"com.topdraw.xhx.fanpai\"}}]}", |
| 329 | "code": "highScore_57aea4b3-7716-4224-bc77-43272c35ee32" | 330 | "code": "highScore_57aea4b3-7716-4224-bc77-43272c35ee32" |
| 330 | } | 331 | } | ... | ... |
| ... | @@ -57,9 +57,10 @@ | ... | @@ -57,9 +57,10 @@ |
| 57 | android:value="EastCity" /> | 57 | android:value="EastCity" /> |
| 58 | 58 | ||
| 59 | <!-- 移动埋点SDK --> | 59 | <!-- 移动埋点SDK --> |
| 60 | <!-- 上线前需要找福建移动验证下是否替换这个正式版的key 9d382a618ebf48a106d4101356a4e5f9--> | ||
| 60 | <meta-data | 61 | <meta-data |
| 61 | android:name="CMCC.APPKEY" | 62 | android:name="CMCC.APPKEY" |
| 62 | android:value="13e71c3ecc4d4b96f1b5b0e5141bd3e6" /> | 63 | android:value="19d1e5ac0d304dc3c82481aecebdc84d" /> |
| 63 | 64 | ||
| 64 | <!-- 未来NewTV --> | 65 | <!-- 未来NewTV --> |
| 65 | <meta-data | 66 | <meta-data | ... | ... |
| ... | @@ -24,8 +24,10 @@ | ... | @@ -24,8 +24,10 @@ |
| 24 | ****************************************************************************/ | 24 | ****************************************************************************/ |
| 25 | package org.cocos2dx.javascript; | 25 | package org.cocos2dx.javascript; |
| 26 | 26 | ||
| 27 | import org.cocos2dx.javascript.common.HttpClientUtil; | ||
| 27 | import org.cocos2dx.javascript.common.OBiPluginLoader; | 28 | import org.cocos2dx.javascript.common.OBiPluginLoader; |
| 28 | import org.cocos2dx.javascript.common.PluginLoader; | 29 | import org.cocos2dx.javascript.common.PluginLoader; |
| 30 | import org.cocos2dx.javascript.component.NativeLogReporterNewTV; | ||
| 29 | import org.cocos2dx.javascript.component.NewTVSDK; | 31 | import org.cocos2dx.javascript.component.NewTVSDK; |
| 30 | import org.cocos2dx.lib.Cocos2dxActivity; | 32 | import org.cocos2dx.lib.Cocos2dxActivity; |
| 31 | import org.cocos2dx.lib.Cocos2dxGLSurfaceView; | 33 | import org.cocos2dx.lib.Cocos2dxGLSurfaceView; |
| ... | @@ -77,6 +79,8 @@ import org.cocos2dx.javascript.component.CocosMediaPlayer; | ... | @@ -77,6 +79,8 @@ import org.cocos2dx.javascript.component.CocosMediaPlayer; |
| 77 | import org.cocos2dx.javascript.common.CommonUtils; | 79 | import org.cocos2dx.javascript.common.CommonUtils; |
| 78 | import org.cocos2dx.javascript.common.MelodyApplication; | 80 | import org.cocos2dx.javascript.common.MelodyApplication; |
| 79 | import org.cocos2dx.javascript.common.TopdrawSDKWrapper; | 81 | import org.cocos2dx.javascript.common.TopdrawSDKWrapper; |
| 82 | import org.json.JSONException; | ||
| 83 | import org.json.JSONObject; | ||
| 80 | 84 | ||
| 81 | public class AppActivity extends Cocos2dxActivity { | 85 | public class AppActivity extends Cocos2dxActivity { |
| 82 | private static String TAG = "AppActivity"; | 86 | private static String TAG = "AppActivity"; |
| ... | @@ -138,6 +142,7 @@ public class AppActivity extends Cocos2dxActivity { | ... | @@ -138,6 +142,7 @@ public class AppActivity extends Cocos2dxActivity { |
| 138 | new Handler().postDelayed(new Runnable() { | 142 | new Handler().postDelayed(new Runnable() { |
| 139 | @Override | 143 | @Override |
| 140 | public void run() { | 144 | public void run() { |
| 145 | //这里重新替换了春哥的SDK,所以可能执行不到 | ||
| 141 | relativeLayout.setVisibility(View.GONE); | 146 | relativeLayout.setVisibility(View.GONE); |
| 142 | } | 147 | } |
| 143 | }, 3 * 1000); //延迟3秒执行 | 148 | }, 3 * 1000); //延迟3秒执行 |
| ... | @@ -185,11 +190,12 @@ public class AppActivity extends Cocos2dxActivity { | ... | @@ -185,11 +190,12 @@ public class AppActivity extends Cocos2dxActivity { |
| 185 | TOPDRAW_APPID = appInfo.metaData.getString("TOPDRAW.APPID"); | 190 | TOPDRAW_APPID = appInfo.metaData.getString("TOPDRAW.APPID"); |
| 186 | TOPDRAW_APPSECRET = appInfo.metaData.getString("TOPDRAW.APPSECRET"); | 191 | TOPDRAW_APPSECRET = appInfo.metaData.getString("TOPDRAW.APPSECRET"); |
| 187 | TOPDRAW_REFER_PATH = TOPDRAW_PLATFORM_SERVER + "/Platform/Logout"; | 192 | TOPDRAW_REFER_PATH = TOPDRAW_PLATFORM_SERVER + "/Platform/Logout"; |
| 188 | TopdrawSDK.init(getApplicationContext(), TOPDRAW_PLATFORM, TOPDRAW_PLATFORM_SERVER, TOPDRAW_APPID, TOPDRAW_APPSECRET, initListener); | 193 | // TopdrawSDK.init(getApplicationContext(), TOPDRAW_PLATFORM, TOPDRAW_PLATFORM_SERVER, TOPDRAW_APPID, TOPDRAW_APPSECRET, initListener); |
| 189 | 194 | ||
| 190 | //移动埋点 | 195 | //移动埋点 |
| 191 | APP_KEY = appInfo.metaData.getString("CMCC.APPKEY"); | 196 | APP_KEY = appInfo.metaData.getString("CMCC.APPKEY"); |
| 192 | APP_NAME = getString(R.string.app_name); | 197 | APP_NAME = getString(R.string.app_name); |
| 198 | APP_TYPE = "游戏"; | ||
| 193 | 199 | ||
| 194 | //init NewTV | 200 | //init NewTV |
| 195 | NewTVSDK.getInstence(this).init(); //注意防止loading图片覆盖掉开机广告 fix jerry | 201 | NewTVSDK.getInstence(this).init(); //注意防止loading图片覆盖掉开机广告 fix jerry |
| ... | @@ -226,6 +232,7 @@ public class AppActivity extends Cocos2dxActivity { | ... | @@ -226,6 +232,7 @@ public class AppActivity extends Cocos2dxActivity { |
| 226 | SDKWrapper.getInstance().onResume(); | 232 | SDKWrapper.getInstance().onResume(); |
| 227 | mRLSingleColor.setVisibility(View.GONE); | 233 | mRLSingleColor.setVisibility(View.GONE); |
| 228 | mOBiLayout.setVisibility(View.GONE); | 234 | mOBiLayout.setVisibility(View.GONE); |
| 235 | relativeLayout.setVisibility(View.GONE); | ||
| 229 | } | 236 | } |
| 230 | 237 | ||
| 231 | @Override | 238 | @Override |
| ... | @@ -238,17 +245,37 @@ public class AppActivity extends Cocos2dxActivity { | ... | @@ -238,17 +245,37 @@ public class AppActivity extends Cocos2dxActivity { |
| 238 | } | 245 | } |
| 239 | 246 | ||
| 240 | @Override | 247 | @Override |
| 248 | protected void onStop() { | ||
| 249 | Log.d("AppActivity", "onStop()...."); | ||
| 250 | super.onStop(); | ||
| 251 | SDKWrapper.getInstance().onStop(); | ||
| 252 | } | ||
| 253 | |||
| 254 | @Override | ||
| 241 | protected void onDestroy() { | 255 | protected void onDestroy() { |
| 242 | super.onDestroy(); | 256 | super.onDestroy(); |
| 257 | //未来SDK退出 | ||
| 258 | NativeLogReporterNewTV nlp = NativeLogReporterNewTV.getInstance(this, null); | ||
| 259 | nlp.report(88, "1"); | ||
| 243 | unregisterReceiver(receiver); | 260 | unregisterReceiver(receiver); |
| 244 | SDKWrapper.getInstance().onDestroy(); | 261 | SDKWrapper.getInstance().onDestroy(); |
| 262 | if (baminSDKInited) { //埋点SDK退出 | ||
| 263 | HashMap<Object, Object> params = new HashMap<>(); | ||
| 264 | params.put("APP_NAME", APP_NAME); | ||
| 265 | params.put("APP_TYPE", APP_TYPE); | ||
| 266 | params.put("USER_LOGIN", "0"); | ||
| 267 | params.put("USER_ID", USER_ID); | ||
| 268 | params.put("USER_ORDER", NativeSystem.isAuthenticated ? "已订购" : "未订购"); | ||
| 269 | // SDKUtil.getInstance().ky_trackCustom(params); | ||
| 270 | // SDKUtil.getInstance().ky_userSignOut(USER_ID); | ||
| 271 | } | ||
| 245 | TopdrawSDK.destory(this, null, new ITopdrawResultListener() { | 272 | TopdrawSDK.destory(this, null, new ITopdrawResultListener() { |
| 246 | @Override | 273 | @Override |
| 247 | public void onResult(int i, String s, Object o) { | 274 | public void onResult(int i, String s, Object o) { |
| 248 | Log.d(TAG, "destory " + i + " " + s); | 275 | Log.d(TAG, "destory " + i + " " + s); |
| 249 | try { | 276 | try { |
| 250 | if (baminSDKInited) { | 277 | if (baminSDKInited) { |
| 251 | SDKUtil.getInstance().ky_quit(); | 278 | SDKUtil.getInstance().ky_quit(); //这里考虑延迟几秒销毁,否则无法触发 |
| 252 | } | 279 | } |
| 253 | System.exit(0); | 280 | System.exit(0); |
| 254 | } catch (Throwable t) { | 281 | } catch (Throwable t) { |
| ... | @@ -277,13 +304,6 @@ public class AppActivity extends Cocos2dxActivity { | ... | @@ -277,13 +304,6 @@ public class AppActivity extends Cocos2dxActivity { |
| 277 | } | 304 | } |
| 278 | 305 | ||
| 279 | @Override | 306 | @Override |
| 280 | protected void onStop() { | ||
| 281 | Log.d("AppActivity", "onStop()...."); | ||
| 282 | super.onStop(); | ||
| 283 | SDKWrapper.getInstance().onStop(); | ||
| 284 | } | ||
| 285 | |||
| 286 | @Override | ||
| 287 | public void onBackPressed() { | 307 | public void onBackPressed() { |
| 288 | SDKWrapper.getInstance().onBackPressed(); | 308 | SDKWrapper.getInstance().onBackPressed(); |
| 289 | super.onBackPressed(); | 309 | super.onBackPressed(); |
| ... | @@ -398,7 +418,7 @@ public class AppActivity extends Cocos2dxActivity { | ... | @@ -398,7 +418,7 @@ public class AppActivity extends Cocos2dxActivity { |
| 398 | if (0 == result) { | 418 | if (0 == result) { |
| 399 | MelodyApplication.sdk = (ITopdrawSDK) obj; | 419 | MelodyApplication.sdk = (ITopdrawSDK) obj; |
| 400 | USER_ID = MelodyApplication.sdk.getOssUserID(); | 420 | USER_ID = MelodyApplication.sdk.getOssUserID(); |
| 401 | Log.d(TAG, "获取token..." + MelodyApplication.sdk.getToken()); | 421 | Log.d(TAG, "USER_ID..." + MelodyApplication.sdk.getOssUserID());//15280011369 |
| 402 | 422 | ||
| 403 | CookieManager.getInstance().setCookie(TOPDRAW_PLATFORM_SERVER, "appId=" + TOPDRAW_APPID); | 423 | CookieManager.getInstance().setCookie(TOPDRAW_PLATFORM_SERVER, "appId=" + TOPDRAW_APPID); |
| 404 | CookieManager.getInstance().setCookie(TOPDRAW_PLATFORM_SERVER, "userId=" + MelodyApplication.sdk.getUserID()); | 424 | CookieManager.getInstance().setCookie(TOPDRAW_PLATFORM_SERVER, "userId=" + MelodyApplication.sdk.getUserID()); |
| ... | @@ -417,34 +437,35 @@ public class AppActivity extends Cocos2dxActivity { | ... | @@ -417,34 +437,35 @@ public class AppActivity extends Cocos2dxActivity { |
| 417 | //局方埋点 | 437 | //局方埋点 |
| 418 | try { | 438 | try { |
| 419 | SDKUtil.isOpenLog = true; | 439 | SDKUtil.isOpenLog = true; |
| 420 | int sdkResult = SDKUtil.getInstance().ky_initWithAppKey(AppActivity.this, APP_KEY, | 440 | // Log.d(TAG, "埋点APP_KEY: " + APP_KEY); |
| 441 | int sdkResult = SDKUtil.getInstance().ky_initWithAppKey(AppActivity.this, APP_KEY, //埋点SDK初始化 | ||
| 421 | getPackageManager().getPackageInfo(getPackageName(), 0).versionName); | 442 | getPackageManager().getPackageInfo(getPackageName(), 0).versionName); |
| 422 | Log.d(TAG, "sdkResult..." + sdkResult); | 443 | Log.d(TAG, "sdkResult..." + sdkResult); |
| 423 | baminSDKInited = (sdkResult == 0); | 444 | baminSDKInited = (sdkResult == 0); |
| 424 | Log.d(TAG, "埋点数据:" + baminSDKInited); | 445 | Log.d(TAG, "埋点数据:" + baminSDKInited); |
| 425 | Map<String, Object> params = new HashMap<>(); | 446 | // Map<String, Object> params = new HashMap<>(); |
| 426 | params.put("appId", TOPDRAW_APPID); | 447 | // params.put("appId", TOPDRAW_APPID); |
| 427 | params.put("userId", MelodyApplication.sdk.getUserID()); | 448 | // params.put("userId", MelodyApplication.sdk.getUserID()); |
| 428 | MelodyApplication.sdk.auth(AppActivity.this, MelodyApplication.sdk.getToken(), params, new ITopdrawResultListener() { | 449 | // MelodyApplication.sdk.auth(AppActivity.this, MelodyApplication.sdk.getToken(), params, new ITopdrawResultListener() { |
| 429 | @Override | 450 | // @Override |
| 430 | public void onResult(int i, String s, Object o) { | 451 | // public void onResult(int i, String s, Object o) { |
| 431 | if (10 == i) { | 452 | // if (10 == i) { |
| 432 | NativeSystem.isAuthenticated = true; | 453 | // NativeSystem.isAuthenticated = true; |
| 433 | } else { | 454 | // } else { |
| 434 | NativeSystem.isAuthenticated = false; | 455 | // NativeSystem.isAuthenticated = false; |
| 435 | } | 456 | // } |
| 436 | if (baminSDKInited) { | 457 | if (baminSDKInited) { //埋点SDK登录 |
| 437 | HashMap<Object, Object> params = new HashMap<>(); | 458 | HashMap<Object, Object> params = new HashMap<>(); |
| 438 | params.put("APP_NAME", APP_NAME); | 459 | params.put("APP_NAME", APP_NAME); |
| 439 | params.put("APP_TYPE", APP_TYPE); | 460 | params.put("APP_TYPE", APP_TYPE); |
| 440 | params.put("USER_LOGIN", "1"); | 461 | params.put("USER_LOGIN", "1"); |
| 441 | params.put("USER_ID", USER_ID); | 462 | params.put("USER_ID", USER_ID); |
| 442 | params.put("USER_ORDER", NativeSystem.isAuthenticated ? "已订购" : "未订购"); | 463 | params.put("USER_ORDER", NativeSystem.isAuthenticated ? "已订购" : "未订购"); |
| 443 | SDKUtil.getInstance().ky_trackCustom(params); | 464 | // SDKUtil.getInstance().ky_trackCustom(params); //先注释。。。。。 |
| 444 | SDKUtil.getInstance().ky_userSignIn(USER_ID); | 465 | // SDKUtil.getInstance().ky_userSignIn(USER_ID); |
| 445 | } | 466 | } |
| 446 | } | 467 | // } |
| 447 | }); | 468 | // }); |
| 448 | } catch (Exception e) { | 469 | } catch (Exception e) { |
| 449 | 470 | ||
| 450 | } | 471 | } | ... | ... |
| ... | @@ -3,9 +3,12 @@ package org.cocos2dx.javascript.common; | ... | @@ -3,9 +3,12 @@ package org.cocos2dx.javascript.common; |
| 3 | import android.content.Context; | 3 | import android.content.Context; |
| 4 | import android.content.pm.PackageInfo; | 4 | import android.content.pm.PackageInfo; |
| 5 | import android.content.pm.PackageManager; | 5 | import android.content.pm.PackageManager; |
| 6 | import android.database.Cursor; | ||
| 6 | import android.net.ConnectivityManager; | 7 | import android.net.ConnectivityManager; |
| 7 | import android.net.NetworkInfo; | 8 | import android.net.NetworkInfo; |
| 9 | import android.net.Uri; | ||
| 8 | import android.text.TextUtils; | 10 | import android.text.TextUtils; |
| 11 | import android.util.Log; | ||
| 9 | 12 | ||
| 10 | import java.io.File; | 13 | import java.io.File; |
| 11 | 14 | ||
| ... | @@ -16,6 +19,8 @@ import java.io.File; | ... | @@ -16,6 +19,8 @@ import java.io.File; |
| 16 | */ | 19 | */ |
| 17 | public class CommonUtils { | 20 | public class CommonUtils { |
| 18 | 21 | ||
| 22 | private static final String TAG = "CommonUtils"; | ||
| 23 | |||
| 19 | public static boolean checkAppInstalled(Context context, String pkgName) { | 24 | public static boolean checkAppInstalled(Context context, String pkgName) { |
| 20 | if (pkgName == null || pkgName.isEmpty()) { | 25 | if (pkgName == null || pkgName.isEmpty()) { |
| 21 | return false; | 26 | return false; |
| ... | @@ -75,4 +80,46 @@ public class CommonUtils { | ... | @@ -75,4 +80,46 @@ public class CommonUtils { |
| 75 | } | 80 | } |
| 76 | return false; | 81 | return false; |
| 77 | } | 82 | } |
| 83 | |||
| 84 | |||
| 85 | public static String getToken(Context context) { | ||
| 86 | String value = ""; | ||
| 87 | Uri uri = Uri.parse("content://stbconfig/authentication/user_token"); | ||
| 88 | Cursor c = null; | ||
| 89 | try { | ||
| 90 | c = context.getContentResolver().query(uri, null, "name = ?", new String[]{"user_token"}, null); // 建议使用这种name=?参数化的查询语句来操作 | ||
| 91 | if (c != null && c.moveToFirst()) { | ||
| 92 | value = c.getString(c.getColumnIndex("value")); | ||
| 93 | } | ||
| 94 | } catch (Exception e) { | ||
| 95 | e.printStackTrace(); | ||
| 96 | } finally { | ||
| 97 | if (c != null) { | ||
| 98 | c.close(); // 游标放到finally块来释放。 | ||
| 99 | } | ||
| 100 | } | ||
| 101 | // Log.d(TAG, "获取机顶盒token..." + value); | ||
| 102 | return value; | ||
| 103 | } | ||
| 104 | |||
| 105 | public static String getServer(Context context) { | ||
| 106 | String value = ""; | ||
| 107 | Uri uri = Uri.parse("content://stbconfig/authentication/epg_server"); | ||
| 108 | Cursor c = null; | ||
| 109 | try { | ||
| 110 | c = context.getContentResolver().query(uri, null, "name = ?", new String[]{"epg_server"}, null); // 建议使用这种name=?参数化的查询语句来操作 | ||
| 111 | if (c != null && c.moveToFirst()) { | ||
| 112 | value = c.getString(c.getColumnIndex("value")); | ||
| 113 | } | ||
| 114 | } catch (Exception e) { | ||
| 115 | e.printStackTrace(); | ||
| 116 | } finally { | ||
| 117 | if (c != null) { | ||
| 118 | c.close(); // 游标放到finally块来释放。 | ||
| 119 | } | ||
| 120 | } | ||
| 121 | // Log.d(TAG, "获取机顶盒token..." + value); | ||
| 122 | return value; | ||
| 123 | } | ||
| 124 | |||
| 78 | } | 125 | } | ... | ... |
| 1 | package org.cocos2dx.javascript.common; | ||
| 2 | |||
| 3 | import android.util.Log; | ||
| 4 | |||
| 5 | import java.io.ByteArrayOutputStream; | ||
| 6 | import java.io.IOException; | ||
| 7 | import java.io.InputStream; | ||
| 8 | import java.io.OutputStreamWriter; | ||
| 9 | import java.net.HttpURLConnection; | ||
| 10 | import java.net.MalformedURLException; | ||
| 11 | import java.net.URL; | ||
| 12 | |||
| 13 | /** | ||
| 14 | * author : Jinwawa | ||
| 15 | * date : 2020/4/13 0013. | ||
| 16 | * desc : | ||
| 17 | */ | ||
| 18 | public class HttpClientUtil { | ||
| 19 | private static final String TAG = "HttpClientUtils"; | ||
| 20 | |||
| 21 | public static void get(final String requestUrl, final HttpClientUtil.OnRequestCallBack callBack) { | ||
| 22 | new Thread() { | ||
| 23 | public void run() { | ||
| 24 | getRequest(requestUrl, callBack); | ||
| 25 | } | ||
| 26 | }.start(); | ||
| 27 | } | ||
| 28 | |||
| 29 | public static void post(final String requestUrl, final String params, final String token,final HttpClientUtil.OnRequestCallBack callBack) { | ||
| 30 | new Thread() { | ||
| 31 | public void run() { | ||
| 32 | postRequest(requestUrl, params,token, callBack); | ||
| 33 | } | ||
| 34 | }.start(); | ||
| 35 | } | ||
| 36 | |||
| 37 | private static void getRequest(String requestUrl, HttpClientUtil.OnRequestCallBack callBack) { | ||
| 38 | boolean isSuccess = false; | ||
| 39 | String message; | ||
| 40 | |||
| 41 | InputStream inputStream = null; | ||
| 42 | ByteArrayOutputStream baos = null; | ||
| 43 | try { | ||
| 44 | URL url = new URL(requestUrl); | ||
| 45 | HttpURLConnection connection = (HttpURLConnection) url.openConnection(); | ||
| 46 | // 设定请求的方法为"POST",默认是GET | ||
| 47 | connection.setRequestMethod("GET"); | ||
| 48 | connection.setConnectTimeout(50000); | ||
| 49 | connection.setReadTimeout(50000); | ||
| 50 | // User-Agent IE9的标识 | ||
| 51 | connection.setRequestProperty("User-Agent", "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;"); | ||
| 52 | connection.setRequestProperty("Accept-Language", "zh-CN"); | ||
| 53 | connection.setRequestProperty("Connection", "Keep-Alive"); | ||
| 54 | connection.setRequestProperty("Charset", "UTF-8"); | ||
| 55 | /* | ||
| 56 | * 当我们要获取我们请求的http地址访问的数据时就是使用connection.getInputStream().read()方式时我们就需要setDoInput(true), | ||
| 57 | * 根据api文档我们可知doInput默认就是为true。我们可以不用手动设置了,如果不需要读取输入流的话那就setDoInput(false)。 | ||
| 58 | * 当我们要采用非get请求给一个http网络地址传参 就是使用connection.getOutputStream().write() 方法时我们就需要setDoOutput(true), 默认是false | ||
| 59 | */ | ||
| 60 | // 设置是否从httpUrlConnection读入,默认情况下是true; | ||
| 61 | connection.setDoInput(true); | ||
| 62 | // 设置是否向httpUrlConnection输出,如果是post请求,参数要放在http正文内,因此需要设为true, 默认是false; | ||
| 63 | //connection.setDoOutput(true);//Android 4.0 GET时候 用这句会变成POST 报错java.io.FileNotFoundException | ||
| 64 | connection.setUseCaches(false); | ||
| 65 | connection.connect();// | ||
| 66 | int contentLength = connection.getContentLength(); | ||
| 67 | if (connection.getResponseCode() == 200) { | ||
| 68 | inputStream = connection.getInputStream();//会隐式调用connect() | ||
| 69 | baos = new ByteArrayOutputStream(); | ||
| 70 | int readLen; | ||
| 71 | byte[] bytes = new byte[1024]; | ||
| 72 | while ((readLen = inputStream.read(bytes)) != -1) { | ||
| 73 | baos.write(bytes, 0, readLen); | ||
| 74 | } | ||
| 75 | String result = baos.toString(); | ||
| 76 | Log.i(TAG, " result:" + result); | ||
| 77 | |||
| 78 | message = result; | ||
| 79 | isSuccess = true; | ||
| 80 | } else { | ||
| 81 | message = "请求失败 code:" + connection.getResponseCode(); | ||
| 82 | } | ||
| 83 | |||
| 84 | } catch (MalformedURLException e) { | ||
| 85 | message = e.getMessage(); | ||
| 86 | e.printStackTrace(); | ||
| 87 | } catch (IOException e) { | ||
| 88 | message = e.getMessage(); | ||
| 89 | e.printStackTrace(); | ||
| 90 | } finally { | ||
| 91 | try { | ||
| 92 | if (baos != null) { | ||
| 93 | baos.close(); | ||
| 94 | } | ||
| 95 | if (inputStream != null) { | ||
| 96 | inputStream.close(); | ||
| 97 | } | ||
| 98 | } catch (IOException e) { | ||
| 99 | message = e.getMessage(); | ||
| 100 | e.printStackTrace(); | ||
| 101 | } | ||
| 102 | } | ||
| 103 | if (isSuccess) { | ||
| 104 | callBack.onSuccess(message); | ||
| 105 | } else { | ||
| 106 | callBack.onError(message); | ||
| 107 | } | ||
| 108 | } | ||
| 109 | |||
| 110 | private static void postRequest(String requestUrl, String params,String token, HttpClientUtil.OnRequestCallBack callBack) { | ||
| 111 | boolean isSuccess = false; | ||
| 112 | String message; | ||
| 113 | InputStream inputStream = null; | ||
| 114 | ByteArrayOutputStream baos = null; | ||
| 115 | try { | ||
| 116 | URL url = new URL(requestUrl); | ||
| 117 | HttpURLConnection connection = (HttpURLConnection) url.openConnection(); | ||
| 118 | // 设定请求的方法为"POST",默认是GET | ||
| 119 | connection.setRequestMethod("POST"); | ||
| 120 | connection.setConnectTimeout(50000); | ||
| 121 | connection.setReadTimeout(50000); | ||
| 122 | // User-Agent IE9的标识 | ||
| 123 | // connection.setRequestProperty("User-Agent", "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;"); | ||
| 124 | connection.setRequestProperty("Accept-Language", "zh-CN"); | ||
| 125 | connection.setRequestProperty("Connection", "close"); | ||
| 126 | connection.setRequestProperty("Charset", "UTF-8"); | ||
| 127 | connection.setRequestProperty("Content-Type", "application/json"); | ||
| 128 | connection.setRequestProperty("Authorization",token); | ||
| 129 | /* | ||
| 130 | * 当我们要获取我们请求的http地址访问的数据时就是使用connection.getInputStream().read()方式时我们就需要setDoInput(true), | ||
| 131 | * 根据api文档我们可知doInput默认就是为true。我们可以不用手动设置了,如果不需要读取输入流的话那就setDoInput(false)。 | ||
| 132 | * 当我们要采用非get请求给一个http网络地址传参 就是使用connection.getOutputStream().write() 方法时我们就需要setDoOutput(true), 默认是false | ||
| 133 | */ | ||
| 134 | // 设置是否从httpUrlConnection读入,默认情况下是true; | ||
| 135 | connection.setDoInput(true); | ||
| 136 | // 设置是否向httpUrlConnection输出,如果是post请求,参数要放在http正文内,因此需要设为true, 默认是false; | ||
| 137 | connection.setDoOutput(true); | ||
| 138 | connection.setUseCaches(false); | ||
| 139 | |||
| 140 | // set params three way OutputStreamWriter | ||
| 141 | OutputStreamWriter out = new OutputStreamWriter( | ||
| 142 | connection.getOutputStream(), "UTF-8"); | ||
| 143 | // 发送请求params参数 | ||
| 144 | out.write(params); | ||
| 145 | out.flush(); | ||
| 146 | connection.connect(); | ||
| 147 | |||
| 148 | int contentLength = connection.getContentLength(); | ||
| 149 | if (connection.getResponseCode() == 200) { | ||
| 150 | // 会隐式调用connect() | ||
| 151 | inputStream = connection.getInputStream(); | ||
| 152 | baos = new ByteArrayOutputStream(); | ||
| 153 | int readLen; | ||
| 154 | byte[] bytes = new byte[1024]; | ||
| 155 | while ((readLen = inputStream.read(bytes)) != -1) { | ||
| 156 | baos.write(bytes, 0, readLen); | ||
| 157 | } | ||
| 158 | String backStr = baos.toString(); | ||
| 159 | Log.i(TAG, "请求成功 backStr:" + backStr); | ||
| 160 | |||
| 161 | message = backStr; | ||
| 162 | isSuccess = true; | ||
| 163 | } else { | ||
| 164 | message = "请求失败 code:" + connection.getResponseCode(); | ||
| 165 | } | ||
| 166 | |||
| 167 | } catch (MalformedURLException e) { | ||
| 168 | message = e.getMessage(); | ||
| 169 | e.printStackTrace(); | ||
| 170 | } catch (IOException e) { | ||
| 171 | message = e.getMessage(); | ||
| 172 | e.printStackTrace(); | ||
| 173 | } finally { | ||
| 174 | try { | ||
| 175 | if (baos != null) { | ||
| 176 | baos.close(); | ||
| 177 | } | ||
| 178 | if (inputStream != null) { | ||
| 179 | inputStream.close(); | ||
| 180 | } | ||
| 181 | } catch (IOException e) { | ||
| 182 | message = e.getMessage(); | ||
| 183 | e.printStackTrace(); | ||
| 184 | } | ||
| 185 | } | ||
| 186 | if (isSuccess) { | ||
| 187 | callBack.onSuccess(message); | ||
| 188 | } else { | ||
| 189 | callBack.onError(message); | ||
| 190 | } | ||
| 191 | } | ||
| 192 | |||
| 193 | public interface OnRequestCallBack { | ||
| 194 | void onSuccess(String json); | ||
| 195 | void onError(String errorMsg); | ||
| 196 | } | ||
| 197 | } |
| ... | @@ -13,17 +13,15 @@ import android.widget.ProgressBar; | ... | @@ -13,17 +13,15 @@ import android.widget.ProgressBar; |
| 13 | import android.widget.RelativeLayout; | 13 | import android.widget.RelativeLayout; |
| 14 | import android.widget.Toast; | 14 | import android.widget.Toast; |
| 15 | 15 | ||
| 16 | //import com.migu.sdk.api.PayCallBack; | 16 | import com.topdraw.forfun_FJYD.R; |
| 17 | //import com.topdraw.component.MiguPaySDK; | ||
| 18 | import com.topdraw.forfun.R; | ||
| 19 | import com.topdraw.sdk.*; | ||
| 20 | 17 | ||
| 21 | import java.io.File; | 18 | import java.io.File; |
| 22 | 19 | ||
| 23 | import org.cocos2dx.javascript.AppActivity; | 20 | import org.cocos2dx.javascript.AppActivity; |
| 21 | import org.cocos2dx.lib.Cocos2dxJavascriptJavaBridge; | ||
| 24 | import org.json.JSONArray; | 22 | import org.json.JSONArray; |
| 25 | import org.json.JSONException; | 23 | import org.json.JSONException; |
| 26 | import org.cocos2dx.lib.Cocos2dxJavascriptJavaBridge; | 24 | import org.json.JSONObject; |
| 27 | 25 | ||
| 28 | public class TopdrawSDKWrapper { | 26 | public class TopdrawSDKWrapper { |
| 29 | 27 | ||
| ... | @@ -31,7 +29,7 @@ public class TopdrawSDKWrapper { | ... | @@ -31,7 +29,7 @@ public class TopdrawSDKWrapper { |
| 31 | private static AppActivity _activity; | 29 | private static AppActivity _activity; |
| 32 | private static TopdrawSDKWrapper _instance = null; | 30 | private static TopdrawSDKWrapper _instance = null; |
| 33 | static boolean pluginLoaded = false; | 31 | static boolean pluginLoaded = false; |
| 34 | static ProgressBar pb_progress; | 32 | private static final String HTTP_AUTHORIZE = "/EPG/interEpg/user/default/authorize"; |
| 35 | 33 | ||
| 36 | private TopdrawSDKWrapper() { | 34 | private TopdrawSDKWrapper() { |
| 37 | } | 35 | } |
| ... | @@ -66,67 +64,72 @@ public class TopdrawSDKWrapper { | ... | @@ -66,67 +64,72 @@ public class TopdrawSDKWrapper { |
| 66 | return MelodyApplication.sdk.getUserID(); | 64 | return MelodyApplication.sdk.getUserID(); |
| 67 | } | 65 | } |
| 68 | 66 | ||
| 69 | /** | 67 | public static void getPlayUrl(final String strJSCallBack) { |
| 70 | * 获取播放地址所使用的Listener | 68 | Log.d(TAG, "getPlayUrl start..." + strJSCallBack); |
| 71 | */ | 69 | String epgServer = CommonUtils.getServer(_activity) + HTTP_AUTHORIZE; |
| 72 | private ITopdrawResultListener onGetPlayURLListener = new ITopdrawResultListener() { | 70 | String token = CommonUtils.getToken(_activity); |
| 73 | @Override | 71 | String supercid = "42dab385e29e4f0f99c3513939815a2c"; //测试用例 电视剧则使用掐头去尾及"-"的mediaCode,电影或单片使用"-1" |
| 74 | public void onResult(int i, String s, Object o) { | 72 | String businessType = "1";// 业务类型,1:vod、2:LIVETV。新cp大多是注入点播,此处填1即可 |
| 75 | Log.d(TAG, "TopdrawSDK onGetPlayURL:[" + i + "]" + s); | 73 | String contentType = "0";// 内容类型,0:视频VOD、1:视频频道、300:节目单。同businessType相似,此处填0即可。 |
| 76 | try { | 74 | String playType = "1";// 必填,根据demo固定为1,文档未说明该字段 |
| 77 | final String strPlayURL = ((JSONArray) o).getJSONObject(0).getString("playurl"); | 75 | String tid = "-1";// 栏目编号,OTT大屏的cp点播注入不涉及绑定栏目,此处统一填写为-1 |
| 78 | //通知js | 76 | String cid = "898abfacb6a34c19b36708ebb43ad044"; //测试用例 电视剧的单集使用掐头去尾及"-"的episodeCode,电影单片使用掐头去尾及"-"的mediaCode |
| 77 | String idflag = "1";// 标识cid和supcid的编号类型,统一传1,标识编号为C2接口的内容code。这个字段必需提供,不提供会导致鉴权失败。 | ||
| 78 | |||
| 79 | JSONObject mapParams = new JSONObject(); | ||
| 80 | try { | ||
| 81 | mapParams.put("supercid", supercid);// 电视剧则使用掐头去尾及"-"的mediaCode,电影或单片使用"-1" | ||
| 82 | mapParams.put("businessType", businessType);// 业务类型,1:vod、2:LIVETV。新cp大多是注入点播,此处填1即可 | ||
| 83 | mapParams.put("contentType", contentType);// 内容类型,0:视频VOD、1:视频频道、300:节目单。同businessType相似,此处填0即可。 | ||
| 84 | mapParams.put("playType", playType);// 必填,根据demo固定为1,文档未说明该字段 | ||
| 85 | mapParams.put("tid", tid);// 栏目编号,OTT大屏的cp点播注入不涉及绑定栏目,此处统一填写为-1 | ||
| 86 | mapParams.put("cid", cid);// 电视剧的单集使用掐头去尾及"-"的episodeCode,电影单片使用掐头去尾及"-"的mediaCode | ||
| 87 | mapParams.put("idflag", idflag);// 标识cid和supcid的编号类型,统一传1,标识编号为C2接口的内容code。这个字段必需提供,不提供会导致鉴权失败。 | ||
| 88 | } catch (JSONException e) { | ||
| 89 | e.printStackTrace(); | ||
| 90 | } | ||
| 91 | |||
| 92 | Log.d(TAG, "token | " + CommonUtils.getToken(_activity) + " server| " + CommonUtils.getServer(_activity)); | ||
| 93 | HttpClientUtil.post(epgServer, mapParams.toString(), token, new HttpClientUtil.OnRequestCallBack() { | ||
| 94 | @Override | ||
| 95 | public void onSuccess(String json) { | ||
| 96 | Log.d(TAG, "成功获取播放链接 | " + json); | ||
| 97 | final String testUrl = "http://mirror.aarnet.edu.au/pub/TED-talks/911Mothers_2010W-480p.mp4"; | ||
| 79 | _activity.runOnGLThread( | 98 | _activity.runOnGLThread( |
| 80 | new Runnable() { | 99 | new Runnable() { |
| 81 | @Override | 100 | @Override |
| 82 | public void run() { | 101 | public void run() { |
| 83 | Cocos2dxJavascriptJavaBridge.evalString("cc.log('" + strPlayURL + "')"); | 102 | Cocos2dxJavascriptJavaBridge.evalString( |
| 103 | "cc.find('Canvas',cc.director.getScene()).getComponent(cc.Topdraw.TVCanvas)." + strJSCallBack + "('" + testUrl + "');" | ||
| 104 | ); | ||
| 84 | } | 105 | } |
| 85 | 106 | ||
| 86 | } | 107 | } |
| 87 | ); | 108 | ); |
| 88 | } catch (JSONException e) { | ||
| 89 | e.printStackTrace(); | ||
| 90 | } catch (Exception e) { | ||
| 91 | e.printStackTrace(); | ||
| 92 | } | ||
| 93 | } | ||
| 94 | 109 | ||
| 95 | }; | 110 | JSONObject joAuthorizeResult = null; |
| 96 | 111 | try { | |
| 97 | private ITopdrawResultListener onAuthListener = new ITopdrawResultListener() { | 112 | joAuthorizeResult = new JSONObject(json); |
| 98 | @Override | 113 | if (null != joAuthorizeResult && "0".equals(joAuthorizeResult.getString("returncode"))) { |
| 99 | public void onResult(int i, String s, Object o) { | 114 | JSONArray jaUrls = joAuthorizeResult.getJSONArray("urls"); |
| 100 | Log.d(TAG, "TopdrawSDK authed:[" + i + "]" + s); | 115 | if (null != jaUrls && jaUrls.length() > 0) { |
| 101 | if (i == 10) { | 116 | JSONObject joUrl = jaUrls.getJSONObject(0); |
| 102 | Log.d(TAG, "auth success"); | 117 | if (null != joUrl) { |
| 103 | //authResult = true; | 118 | String strPlayURL = joUrl.getString("playurl"); |
| 104 | } else if (i == -2010) { | 119 | } |
| 105 | //authResult = false; | 120 | } |
| 106 | //sdk.order(context,token,null,orderListener); | 121 | } |
| 107 | Log.d(TAG, "auth failed"); | 122 | } catch (Exception e) { |
| 123 | |||
| 124 | } | ||
| 108 | } | 125 | } |
| 109 | } | ||
| 110 | 126 | ||
| 111 | }; | 127 | @Override |
| 112 | 128 | public void onError(String errorMsg) { | |
| 113 | 129 | Log.d(TAG, "获取播放链接失败| " + errorMsg); | |
| 114 | private ITopdrawResultListener onOrderListener = new ITopdrawResultListener() { | ||
| 115 | @Override | ||
| 116 | public void onResult(int i, String s, Object o) { | ||
| 117 | Log.d(TAG, "TopdrawSDK ordered:[" + i + "]" + s); | ||
| 118 | if (i == 20) { | ||
| 119 | //authResult = true; | ||
| 120 | Log.d(TAG, "Order Success"); | ||
| 121 | //WritableMap event = Arguments.createMap(); | ||
| 122 | //event.putString("result","succeess"); | ||
| 123 | //dispatchEvent("orderSuccess",event); | ||
| 124 | } else { | ||
| 125 | Log.d(TAG, "order failed"); | ||
| 126 | } | 130 | } |
| 127 | // playCallback = null; | 131 | }); |
| 128 | } | 132 | } |
| 129 | }; | ||
| 130 | 133 | ||
| 131 | public static void isExistApk(String apkName, final String strJSCallBack) { | 134 | public static void isExistApk(String apkName, final String strJSCallBack) { |
| 132 | final boolean flag = PluginLoader.getInstance().isExistApk(apkName); | 135 | final boolean flag = PluginLoader.getInstance().isExistApk(apkName); |
| ... | @@ -156,6 +159,7 @@ public class TopdrawSDKWrapper { | ... | @@ -156,6 +159,7 @@ public class TopdrawSDKWrapper { |
| 156 | } | 159 | } |
| 157 | pluginLoaded = true; | 160 | pluginLoaded = true; |
| 158 | final String packageName = apkName; | 161 | final String packageName = apkName; |
| 162 | // final String className = "com.orbbec.u3d.OrbbecActivity"; | ||
| 159 | final String className = "org.cocos2dx.lua.AppActivity"; | 163 | final String className = "org.cocos2dx.lua.AppActivity"; |
| 160 | PluginLoader.getInstance().start(packageName, new PluginLoader.OnResultListener() { | 164 | PluginLoader.getInstance().start(packageName, new PluginLoader.OnResultListener() { |
| 161 | @Override | 165 | @Override | ... | ... |
-
Please register or sign in to post a comment