Browse Source

[FC]:上传微信SDK部分

fengcong 5 years ago
parent
commit
6d3dde36aa

BIN
build/jsb-link/frameworks/runtime-src/proj.android-studio/.idea/caches/build_file_checksums.ser


+ 5 - 0
build/jsb-link/frameworks/runtime-src/proj.android-studio/.idea/jarRepositories.xml

@@ -36,5 +36,10 @@
       <option name="name" value="D:\Android\SDK\extras\android\m2repository" />
       <option name="url" value="file:/D:/Android/SDK/extras/android/m2repository" />
     </remote-repository>
+    <remote-repository>
+      <option name="id" value="MavenRepo" />
+      <option name="name" value="MavenRepo" />
+      <option name="url" value="https://repo.maven.apache.org/maven2/" />
+    </remote-repository>
   </component>
 </project>

+ 2 - 2
build/jsb-link/frameworks/runtime-src/proj.android-studio/.idea/modules/-1746423203/libcocos2dx.iml

@@ -33,10 +33,10 @@
       <sourceFolder url="file://D:/Develop/CocosDashboard_1.0.9/resources/.editors/Creator/2.4.5/resources/cocos2d-x/cocos/platform/android/java/src" isTestSource="false" />
     </content>
     <content url="file://D:/Develop/CocosDashboard_1.0.9/resources/.editors/Creator/2.4.5/resources/cocos2d-x/cocos/platform/android/libcocos2dx">
-      <sourceFolder url="file://D:/Develop/CocosDashboard_1.0.9/resources/.editors/Creator/2.4.5/resources/cocos2d-x/cocos/platform/android/libcocos2dx/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
+      <sourceFolder url="file://D:/Develop/CocosDashboard_1.0.9/resources/.editors/Creator/2.4.5/resources/cocos2d-x/cocos/platform/android/libcocos2dx/build/generated/source/apt/debug" isTestSource="false" generated="true" />
       <sourceFolder url="file://D:/Develop/CocosDashboard_1.0.9/resources/.editors/Creator/2.4.5/resources/cocos2d-x/cocos/platform/android/libcocos2dx/build/generated/source/aidl/debug" isTestSource="false" generated="true" />
+      <sourceFolder url="file://D:/Develop/CocosDashboard_1.0.9/resources/.editors/Creator/2.4.5/resources/cocos2d-x/cocos/platform/android/libcocos2dx/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
       <sourceFolder url="file://D:/Develop/CocosDashboard_1.0.9/resources/.editors/Creator/2.4.5/resources/cocos2d-x/cocos/platform/android/libcocos2dx/build/generated/source/rs/debug" isTestSource="false" generated="true" />
-      <sourceFolder url="file://D:/Develop/CocosDashboard_1.0.9/resources/.editors/Creator/2.4.5/resources/cocos2d-x/cocos/platform/android/libcocos2dx/build/generated/source/apt/debug" isTestSource="false" generated="true" />
       <sourceFolder url="file://D:/Develop/CocosDashboard_1.0.9/resources/.editors/Creator/2.4.5/resources/cocos2d-x/cocos/platform/android/libcocos2dx/build/generated/res/rs/debug" type="java-resource" generated="true" />
       <sourceFolder url="file://D:/Develop/CocosDashboard_1.0.9/resources/.editors/Creator/2.4.5/resources/cocos2d-x/cocos/platform/android/libcocos2dx/build/generated/res/resValues/debug" type="java-resource" generated="true" />
       <sourceFolder url="file://D:/Develop/CocosDashboard_1.0.9/resources/.editors/Creator/2.4.5/resources/cocos2d-x/cocos/platform/android/libcocos2dx/build/generated/source/apt/androidTest/debug" isTestSource="true" generated="true" />

+ 3 - 2
build/jsb-link/frameworks/runtime-src/proj.android-studio/.idea/modules/app/mk_framework.iml

@@ -40,15 +40,15 @@
       <sourceFolder url="file://$MODULE_DIR$/../../../../Classes" isTestSource="false" />
     </content>
     <content url="file://$MODULE_DIR$/../../../app">
+      <sourceFolder url="file://$MODULE_DIR$/../../../app/build/generated/source/apt/debug" isTestSource="false" generated="true" />
       <sourceFolder url="file://$MODULE_DIR$/../../../app/build/generated/source/aidl/debug" isTestSource="false" generated="true" />
       <sourceFolder url="file://$MODULE_DIR$/../../../app/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
-      <sourceFolder url="file://$MODULE_DIR$/../../../app/build/generated/source/apt/debug" isTestSource="false" generated="true" />
       <sourceFolder url="file://$MODULE_DIR$/../../../app/build/generated/source/rs/debug" isTestSource="false" generated="true" />
       <sourceFolder url="file://$MODULE_DIR$/../../../app/build/generated/res/rs/debug" type="java-resource" generated="true" />
       <sourceFolder url="file://$MODULE_DIR$/../../../app/build/generated/res/resValues/debug" type="java-resource" generated="true" />
       <sourceFolder url="file://$MODULE_DIR$/../../../app/build/generated/source/apt/androidTest/debug" isTestSource="true" generated="true" />
-      <sourceFolder url="file://$MODULE_DIR$/../../../app/build/generated/source/buildConfig/androidTest/debug" isTestSource="true" generated="true" />
       <sourceFolder url="file://$MODULE_DIR$/../../../app/build/generated/source/aidl/androidTest/debug" isTestSource="true" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/../../../app/build/generated/source/buildConfig/androidTest/debug" isTestSource="true" generated="true" />
       <sourceFolder url="file://$MODULE_DIR$/../../../app/build/generated/source/rs/androidTest/debug" isTestSource="true" generated="true" />
       <sourceFolder url="file://$MODULE_DIR$/../../../app/build/generated/res/rs/androidTest/debug" type="java-test-resource" generated="true" />
       <sourceFolder url="file://$MODULE_DIR$/../../../app/build/generated/res/resValues/androidTest/debug" type="java-test-resource" generated="true" />
@@ -268,6 +268,7 @@
     <orderEntry type="library" name="Gradle: ./../../../../../../../Develop/CocosDashboard_1.0.9/resources/.editors/Creator/2.4.5/resources/cocos2d-x/cocos/platform/android/java/libs/com.android.vending.expansion.zipfile.jar" level="project" />
     <orderEntry type="library" name="Gradle: ./../../../../../../../Develop/CocosDashboard_1.0.9/resources/.editors/Creator/2.4.5/resources/cocos2d-x/cocos/platform/android/java/libs/okhttp-3.12.7.jar" level="project" />
     <orderEntry type="library" name="Gradle: ./../../../../../../../Develop/CocosDashboard_1.0.9/resources/.editors/Creator/2.4.5/resources/cocos2d-x/cocos/platform/android/java/libs/okio-1.15.0.jar" level="project" />
+    <orderEntry type="library" name="Gradle: com.tencent.mm.opensdk:wechat-sdk-android-without-mta:6.7.4@aar" level="project" />
     <orderEntry type="module" module-name="libcocos2dx" />
   </component>
 </module>

File diff suppressed because it is too large
+ 0 - 0
build/jsb-link/frameworks/runtime-src/proj.android-studio/app/.externalNativeBuild/ndkBuild/debug/armeabi-v7a/ndkBuild_build_output.txt


File diff suppressed because it is too large
+ 1 - 0
build/jsb-link/frameworks/runtime-src/proj.android-studio/app/.externalNativeBuild/ndkBuild/release/armeabi-v7a/ndkBuild_build_output.txt


+ 13 - 0
build/jsb-link/frameworks/runtime-src/proj.android-studio/app/AndroidManifest.xml

@@ -5,6 +5,9 @@
 
     <uses-feature android:glEsVersion="0x00020000" />
 
+    <!--WX SDK for mta statistics, not necessary-->
+    <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
+
     <uses-permission android:name="android.permission.INTERNET"/>
     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
     <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
@@ -32,6 +35,16 @@
                 <category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>
         </activity>
+
+        <activity
+            android:name=".wxapi.WXEntryActivity"
+            android:label="@string/app_name"
+            android:theme="@android:style/Theme.Translucent.NoTitleBar"
+            android:exported="true"
+            android:taskAffinity="com.aries.ttaxx"
+            android:launchMode="singleTask">
+        </activity>
+
     </application>
     
 </manifest>

+ 4 - 0
build/jsb-link/frameworks/runtime-src/proj.android-studio/app/build.gradle

@@ -152,4 +152,8 @@ dependencies {
     implementation fileTree(dir: 'libs', include: ['*.jar','*.aar'])
     implementation fileTree(dir: "${System.getenv("COCOSCREATOR_HOME")}/resources/.editors/Creator/2.4.5/resources/cocos2d-x/cocos/platform/android/java/libs", include: ['*.jar'])
     implementation project(':libcocos2dx')
+
+    //微信SDK(登录、分享等)
+    api 'com.tencent.mm.opensdk:wechat-sdk-android-without-mta:+'
+
 }

+ 160 - 0
build/jsb-link/frameworks/runtime-src/proj.android-studio/app/src/com/aries/ttaxx/wxapi/WXEntryActivity.java

@@ -0,0 +1,160 @@
+package com.aries.ttaxx.wxapi;
+
+import android.app.Activity;
+import android.app.ProgressDialog;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+import android.util.Log;
+import android.widget.Toast;
+
+
+
+//import org.cocos2dx.javascript.thridSdk.ThirdSdkMgr;
+
+import com.aries.ttaxx.BuildConfig;
+import com.tencent.mm.opensdk.modelbase.BaseReq;
+import com.tencent.mm.opensdk.modelbase.BaseResp;
+import com.tencent.mm.opensdk.modelmsg.SendAuth;
+import com.tencent.mm.opensdk.openapi.IWXAPI;
+import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;
+import com.tencent.mm.opensdk.openapi.WXAPIFactory;
+
+import org.cocos2dx.javascript.AppActivity;
+import org.cocos2dx.javascript.thirdSdk.ThirdSdkMgr;
+
+public class WXEntryActivity extends Activity implements IWXAPIEventHandler {
+
+    //单例模式
+    public static WXEntryActivity mInstance = null;
+
+    public static WXEntryActivity getInstance() {
+        if (null == mInstance) {
+            mInstance = new WXEntryActivity();
+        }
+        return mInstance;
+    }
+
+    //AppId(这边统一调用 BuildConfig)
+    private String AppId_WX = "wx28356dc7c541ea76";
+
+    //日志Tag
+    private  String _tag = "[WXEntryActivity] :";
+
+    private IWXAPI iwxapi;
+    private String unionid;
+    private String openid;
+    private WXEntryActivity mContext;
+    private ProgressDialog mProgressDialog;
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+
+        Log.d(this._tag, "onCreate");
+        //可以注释,因为不会自动进入这边的 onCreate() 方法 只不过需要打开该Activty才会进入
+        String APP_ID = BuildConfig.WX_APP_ID;
+        iwxapi = WXAPIFactory.createWXAPI(this, APP_ID, true);
+        handleIntent(getIntent());
+    }
+
+    /** 注册微信
+     *  @param context 调用注册的Activity 一般是AppActivity
+     */
+    public void regToWx(Context context)
+    {
+        String APP_ID = BuildConfig.WX_APP_ID;
+        Log.d(this._tag, "regToWx APP_ID: " + APP_ID);
+        iwxapi = WXAPIFactory.createWXAPI(context, APP_ID, true);
+        iwxapi.registerApp(APP_ID);
+    }
+
+    /** 开始微信授权
+     *  @param context 一般是主Activity 比如 AppActivity
+     */
+    public void startWxAuth(Context context) {
+        Log.d(this._tag, "startWxAuth ");
+        if (!iwxapi.isWXAppInstalled()) {
+            //Toast 是一个 View 视图,快速的为用户显示少量的信息。Toast 在应用程序上浮动显示信息给用户,它永远不会获得焦点,不影响用户的输入等操作,主要用于 一些帮助 / 提示。
+            Toast.makeText(context, "您的设备未安装微信客户端", Toast.LENGTH_SHORT).show();
+        } else {
+            final SendAuth.Req req = new SendAuth.Req();
+            req.scope = "snsapi_userinfo";
+            //req.state = "wechat_sdk_demo_test";
+            req.state = String.valueOf(System.currentTimeMillis());
+            iwxapi.sendReq(req);
+        }
+    }
+
+    @Override
+    protected void onNewIntent(Intent intent) {
+        super.onNewIntent(intent);
+        Log.d(this._tag, "onNewIntent");
+        this.handleIntent(intent);
+    }
+
+    private void handleIntent(Intent intent) {
+        setIntent(intent);
+        iwxapi.handleIntent(intent, this);
+    }
+
+    @Override
+    public void onReq(BaseReq baseReq) {
+
+        Log.d(this._tag, "onReq");
+    }
+
+    //请求回调结果处理
+    @Override
+    public void onResp(BaseResp baseResp) {
+        //登录微信返回回调
+        Log.d(this._tag, "onResp baseResp.errCode: "+baseResp.errCode + "");
+        switch (baseResp.errCode) {
+            case BaseResp.ErrCode.ERR_OK:
+                if (baseResp instanceof SendAuth.Resp) {
+                    String code = ((SendAuth.Resp) baseResp).code;
+//                    ThirdSdkMgr.AccessToken(code);
+                    finish();
+
+                } else {
+                    finish();
+                }
+                break;
+            case BaseResp.ErrCode.ERR_AUTH_DENIED://用户拒绝授权
+                finish();
+                break;
+            case BaseResp.ErrCode.ERR_USER_CANCEL://用户取消
+                finish();
+                break;
+            default:
+                finish();
+                break;
+        }
+    }
+
+
+//    //新写法 分返回code 可以后续借鉴
+//    public void onResp(BaseResp resp) {
+//        if (resp.errCode == BaseResp.ErrCode.ERR_OK) {
+//            if (resp.getType() == ConstantsAPI.COMMAND_SENDAUTH) {
+//                //授权登录成功
+//                String code = ((SendAuth.Resp) resp).code;
+//                String state = ((SendAuth.Resp) resp).state;
+//                Log.d(TAG, "code:===" + code + "state:===" + state);
+//                EventBus.getDefault().post(new ThirdLoginModel(code, state));
+//            } else if (resp.getType() == ConstantsAPI.COMMAND_SENDMESSAGE_TO_WX) {
+//                //分享微信回调
+//                Log.d(TAG, "====返回了====");
+//                String _type = MyWxManager.getInstance().getShareOrigin();
+//                String _target = MyWxManager.getInstance().getShareType();
+//                String _page = MyWxManager.getInstance().getSharePage();
+//                if (!TextUtils.isEmpty(_type) && !TextUtils.isEmpty(_target) && !TextUtils.isEmpty(_page)) {
+//                    MobclickUtil.Share(FrameApplication.getContext(), _type, _target, _page);
+//                }
+//            }
+//            finish();
+//        } else {
+//            finish();
+//        }
+//    }
+}

+ 5 - 0
build/jsb-link/frameworks/runtime-src/proj.android-studio/app/src/org/cocos2dx/javascript/AppActivity.java

@@ -24,6 +24,7 @@ THE SOFTWARE.
 ****************************************************************************/
 package org.cocos2dx.javascript;
 
+import org.cocos2dx.javascript.thirdSdk.ThirdSdkMgr;
 import org.cocos2dx.lib.Cocos2dxActivity;
 import org.cocos2dx.lib.Cocos2dxGLSurfaceView;
 
@@ -49,6 +50,10 @@ public class AppActivity extends Cocos2dxActivity {
         // DO OTHER INITIALIZATION BELOW
         SDKWrapper.getInstance().init(this);
 
+        //赋值方便调用
+        ThirdSdkMgr.appActivity = this;
+        //注册到微信
+        ThirdSdkMgr.regToWx();
     }
 
     @Override

+ 26 - 0
build/jsb-link/frameworks/runtime-src/proj.android-studio/app/src/org/cocos2dx/javascript/thirdSdk/ThirdSdkMgr.java

@@ -0,0 +1,26 @@
+package org.cocos2dx.javascript.thirdSdk;
+
+import android.content.Context;
+import android.util.Log;
+
+import org.cocos2dx.javascript.AppActivity;
+import com.aries.ttaxx.wxapi.WXEntryActivity;
+
+public class ThirdSdkMgr {
+
+    private static String _Tag = "[ThirdMgr]-------:";
+    /**  */
+    public static AppActivity appActivity = null;
+    /** */
+    public static WXEntryActivity wxEntryActivity = null;
+
+    public static void regToWx()
+    {
+        WXEntryActivity.getInstance().regToWx(ThirdSdkMgr.appActivity);
+    }
+
+    public static void WxAuth()
+    {
+        WXEntryActivity.getInstance().startWxAuth(ThirdSdkMgr.appActivity);
+    }
+}

+ 2 - 0
build/jsb-link/frameworks/runtime-src/proj.android-studio/build.gradle

@@ -5,6 +5,7 @@ buildscript {
     repositories {
         google()
         jcenter()
+        mavenCentral()
     }
     dependencies {
         classpath 'com.android.tools.build:gradle:3.2.0'
@@ -19,6 +20,7 @@ allprojects {
     repositories {
         google()
         jcenter()
+        mavenCentral()
         flatDir {
             dirs 'libs'
         }

Some files were not shown because too many files changed in this diff