فهرست منبع

1. 微信登录

咸光金 4 سال پیش
والد
کامیت
782c1b0da7

+ 29 - 30
app/src/main/AndroidManifest.xml

@@ -19,9 +19,10 @@
     <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
     <uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" />
     <uses-permission android:name="com.android.launcher.permission.READ_SETTINGS" />
-    <queries>
+
+    <queries >
         <package android:name="com.tencent.mm" />
-    </queries>
+    </queries >
     <application
 
         android:name="com.quansu.heifengwuliu.App"
@@ -42,33 +43,29 @@
             android:name="design_height_in_dp"
             android:value="667" />
 
-
         <activity android:name="com.quansu.heifengwuliu.activity.SettingsActivity" />
 
-
-<!--                    android:theme="@style/AppTheme.Launcher"
--->
-        <activity android:name=".activity.HomeActivity"
+        <!--                    android:theme="@style/AppTheme.Launcher"
+        -->
+        <activity
+            android:name=".activity.HomeActivity"
             android:screenOrientation="portrait"
-            android:theme="@style/HomeTheme"
-            >
-<!--            <intent-filter>-->
-<!--                <action android:name="android.intent.action.MAIN" />-->
-<!--                <category android:name="android.intent.category.LAUNCHER" />-->
-<!--            </intent-filter>-->
-        </activity>
-
-        <activity android:name=".activity.OneLoginActivity"
-            android:launchMode="singleTask"
-            >
-            <intent-filter>
+            android:theme="@style/HomeTheme" >
+            <!--            <intent-filter>-->
+            <!--                <action android:name="android.intent.action.MAIN" />-->
+            <!--                <category android:name="android.intent.category.LAUNCHER" />-->
+            <!--            </intent-filter>-->
+        </activity >
+
+        <activity
+            android:name=".activity.OneLoginActivity"
+            android:launchMode="singleTask" >
+            <intent-filter >
                 <action android:name="android.intent.action.MAIN" />
                 <category android:name="android.intent.category.LAUNCHER" />
-            </intent-filter>
-
-        </activity>
-
+            </intent-filter >
 
+        </activity >
 
         <activity android:name="com.quansu.heifengwuliu.activity.TodosActivity" />
 
@@ -77,20 +74,22 @@
         <activity
             android:name="com.quansu.heifengwuliu.activity.PrivateCenterActivity"
             android:launchMode="singleTask" >
-<!--            <intent-filter >-->
-<!--                <action android:name="android.intent.action.MAIN" />-->
-<!--                <category android:name="android.intent.category.LAUNCHER" />-->
-<!--            </intent-filter >-->
+            <!--            <intent-filter >-->
+            <!--                <action android:name="android.intent.action.MAIN" />-->
+            <!--                <category android:name="android.intent.category.LAUNCHER" />-->
+            <!--            </intent-filter >-->
         </activity >
         <activity android:name="com.quansu.heifengwuliu.activity.AboutActivity" />
         <activity android:name="com.quansu.heifengwuliu.activity.WebViewActivity" />
         <activity
             android:name="com.quansu.heifengwuliu.activity.SplashActivity"
             android:theme="@style/AppTheme.Launcher" />
-        <activity android:name=".wxapi.WXEntryActivity"
-            android:exported="true"
-            android:launchMode="singleTop"/>
 
+        <activity
+            android:name=".wxapi.WXEntryActivity"
+            android:exported="true"
+            android:launchMode="singleTask"
+            android:taskAffinity="com.quansu.heifengwuliu" />
 
     </application >
 

+ 0 - 1
app/src/main/java/com/quansu/heifengwuliu/activity/OneLoginActivity.kt

@@ -84,7 +84,6 @@ class OneLoginActivity : MBActivity<OneLoginVModel, ActivityOneloginBinding>(){
     fun setLoginCode(code: String) {
         Log.e("-shy-", "wxcode2=: "+code)
         //todo:去请求微信登录的接口
-
         vm.login(code)
     }
 

+ 0 - 5
app/src/main/java/com/quansu/heifengwuliu/vmodel/HomeVModel.kt

@@ -5,13 +5,8 @@ import com.ysnows.base.base.BViewModel
 
 open class HomeVModel : BViewModel<HomeRepository>() {
 
-
-
     fun getUserInfo() {
         repository().login("")
     }
 
-
-
-
 }

+ 28 - 8
app/src/main/java/com/quansu/heifengwuliu/wxapi/WXEntryActivity.kt

@@ -13,18 +13,38 @@ import com.tencent.mm.opensdk.modelmsg.SendAuth
 import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler
 import com.tencent.mm.opensdk.openapi.WXAPIFactory
 import com.ysnows.base.utils.Toasts
-import kotlin.math.log
 
 /**
  *Created by shihuiyun
  *on 2020/9/10
  */
-class WXEntryActivity : Activity() , IWXAPIEventHandler{
+class WXEntryActivity : Activity(), IWXAPIEventHandler {
 
-    override fun onResp(p0: BaseResp?) {
-
-//    override fun onResp(p0: BaseResp) {
+    override fun onResp(baseResp: BaseResp?) {
         //微信主动请求我们
+
+        when (baseResp?.errCode) {
+            BaseResp.ErrCode.ERR_OK -> {
+                if (baseResp is SendAuth.Resp) {
+                    //微信登录的回调
+                    //获取微信传回的code
+                    val code = baseResp.code
+                    RxBus.get().post(ConfigRx.ADD_SEND_CODE, code)
+                    return
+                }
+                if (baseResp?.getType() == ConstantsAPI.COMMAND_SENDMESSAGE_TO_WX) {
+                    Toasts.toast(this@WXEntryActivity, "分享成功")
+                }
+            }
+            BaseResp.ErrCode.ERR_USER_CANCEL -> {
+            }
+            BaseResp.ErrCode.ERR_AUTH_DENIED -> {
+            }
+            else -> {
+            }
+        }
+
+
         prompt()
     }
 
@@ -32,7 +52,7 @@ class WXEntryActivity : Activity() , IWXAPIEventHandler{
 
 //    override fun onReq(baseResp: BaseReq) {
 
-        Log.e("-shy-", "wxcode=: "+baseResp.hashCode())
+        Log.e("-shy-", "wxcode=: " + baseResp.hashCode())
 
         when (baseResp.hashCode()) {
             BaseResp.ErrCode.ERR_OK -> {
@@ -42,7 +62,7 @@ class WXEntryActivity : Activity() , IWXAPIEventHandler{
                     //获取微信传回的code
                     val code = newResp.code
 
-                    Log.e("-shy-", "wxcode1=: "+code)
+                    Log.e("-shy-", "wxcode1=: " + code)
                     RxBus.get().post(ConfigRx.ADD_SEND_CODE, code)
 
                     return
@@ -68,7 +88,7 @@ class WXEntryActivity : Activity() , IWXAPIEventHandler{
 
     override fun onCreate(savedInstanceState: Bundle?) {
         super.onCreate(savedInstanceState)
-        Log.e("onCreate", "onCreate: " )
+        Log.e("onCreate", "onCreate: ")
         RxBus.get().register(this)
         val mWXApi = WXAPIFactory.createWXAPI(this, WeChatUtil.WECHAT_APP_ID, true)
         mWXApi.handleIntent(intent, this)