升级 Android 微信 SDK

This commit is contained in:
v7lin
2019-08-01 22:08:03 +08:00
parent 6f3fb67bdb
commit fea0f2b644
8 changed files with 76 additions and 38 deletions

View File

@ -62,10 +62,6 @@ steps:
from_secret: CODECOV_TOKEN
files:
- ./coverage/lcov.info
when:
event:
exclude:
- pull_request
- name: publish-check
image: v7lin/flutter:1.7.8-hotfix.3-stable
@ -91,9 +87,10 @@ steps:
volumes:
- name: pub-cache
path: /opt/flutter/.pub-cache
environment:
PUB_CACHE: /opt/flutter/.pub-cache
commands:
- FLUTTER_HOME=/opt/flutter/.pub-cache
- wget -P $FLUTTER_HOME https://raw.githubusercontent.com/v7lin/pub_credentials/master/credentials.json.enc
- wget -P $PUB_CACHE https://raw.githubusercontent.com/v7lin/pub_credentials/master/credentials.json.enc
- name: restore-cache-openssl
image: v7lin/openssl:1.1.1b
@ -101,14 +98,14 @@ steps:
- name: pub-cache
path: /opt/flutter/.pub-cache
environment:
PUB_CACHE: /opt/flutter/.pub-cache
ENC_METHOD:
from_secret: ENC_METHOD
ENC_PASSWORD:
from_secret: ENC_PASSWORD
commands:
- FLUTTER_HOME=/opt/flutter/.pub-cache
- openssl enc -d -$ENC_METHOD -k $ENC_PASSWORD -in $FLUTTER_HOME/credentials.json.enc -out $FLUTTER_HOME/credentials.json
- rm $FLUTTER_HOME/credentials.json.enc
- openssl enc -d -$ENC_METHOD -k $ENC_PASSWORD -in $PUB_CACHE/credentials.json.enc -out $PUB_CACHE/credentials.json
- rm $PUB_CACHE/credentials.json.enc
- name: publish
image: v7lin/flutter:1.7.8-hotfix.3-stable
@ -124,14 +121,14 @@ steps:
- name: pub-cache
path: /opt/flutter/.pub-cache
environment:
PUB_CACHE: /opt/flutter/.pub-cache
ENC_METHOD:
from_secret: ENC_METHOD
ENC_PASSWORD:
from_secret: ENC_PASSWORD
commands:
- FLUTTER_HOME=/opt/flutter/.pub-cache
- openssl enc -e -$ENC_METHOD -k $ENC_PASSWORD -in $FLUTTER_HOME/credentials.json -out $FLUTTER_HOME/credentials.json.enc
- rm /opt/flutter/.pub-cache/credentials.json
- openssl enc -e -$ENC_METHOD -k $ENC_PASSWORD -in $PUB_CACHE/credentials.json -out $PUB_CACHE/credentials.json.enc
- rm $PUB_CACHE/credentials.json
- name: save-cache
image: docker:git
@ -139,6 +136,7 @@ steps:
- name: pub-cache
path: /opt/flutter/.pub-cache
environment:
PUB_CACHE: /opt/flutter/.pub-cache
GIT_USER_EMAIL:
from_secret: GIT_USER_EMAIL
GIT_USER_NAME:
@ -146,14 +144,13 @@ steps:
GIT_USER_PASSWORD:
from_secret: GIT_USER_PASSWORD # '@''%40' -> URLEncoder.encode("@","utf-8");
commands:
- FLUTTER_HOME=/opt/flutter/.pub-cache
- git config --global user.email $GIT_USER_EMAIL
- git config --global user.name $GIT_USER_NAME
- git config --global credential.helper store
- git clone -b master https://$GIT_USER_NAME:$GIT_USER_PASSWORD@github.com/v7lin/pub_credentials.git $FLUTTER_HOME/pub_credentials
- rm $FLUTTER_HOME/pub_credentials/credentials.json.enc
- mv $FLUTTER_HOME/credentials.json.enc $FLUTTER_HOME/pub_credentials/credentials.json.enc
- cd $FLUTTER_HOME/pub_credentials
- git clone -b master https://$GIT_USER_NAME:$GIT_USER_PASSWORD@github.com/v7lin/pub_credentials.git $PUB_CACHE/pub_credentials
- rm $PUB_CACHE/pub_credentials/credentials.json.enc
- mv $PUB_CACHE/credentials.json.enc $PUB_CACHE/pub_credentials/credentials.json.enc
- cd $PUB_CACHE/pub_credentials
- git commit -am "update credentials by ci/cd tools"
- git push

View File

@ -28,15 +28,18 @@ android {
defaultConfig {
minSdkVersion 16
// library 混淆 -> 随 library 引用,自动添加到 apk 打包混淆
consumerProguardFiles 'consumer-proguard-rules.txt'
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
lintOptions {
disable 'InvalidPackage'
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'io.github.v7lin:wechat-android:5.3.1+1'
implementation 'com.tencent.mm.opensdk:wechat-sdk-android-without-mta:5.4.3'
}

View File

@ -0,0 +1,5 @@
#
-keep class com.tencent.mm.opensdk.** {*;}
-keep class com.tencent.wxop.** {*;}
-keep class com.tencent.mm.sdk.** {*;}

View File

@ -2,25 +2,30 @@
package="io.github.v7lin.fakewechat">
<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" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application>
<activity
android:name=".WechatCallbackActivity"
android:launchMode="singleTop"
android:theme="@style/fake_wechat.Theme.Transparent" />
android:theme="@style/fake_wechat.Theme.Transparent"
android:exported="true"
android:launchMode="singleTask"
android:taskAffinity="${applicationId}" />
<activity-alias
android:name="${applicationId}.wxapi.WXEntryActivity"
android:theme="@style/fake_wechat.Theme.Transparent"
android:exported="true"
android:launchMode="singleTask"
android:taskAffinity="${applicationId}"
android:targetActivity=".WechatCallbackActivity" />
<activity-alias
android:name="${applicationId}.wxapi.WXPayEntryActivity"
android:theme="@style/fake_wechat.Theme.Transparent"
android:exported="true"
android:launchMode="singleTask"
android:taskAffinity="${applicationId}"
android:targetActivity=".WechatCallbackActivity" />
</application>
</manifest>

View File

@ -1,9 +1,13 @@
package io.github.v7lin.fakewechat;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.Uri;
import com.tencent.mm.opensdk.constants.Build;
import com.tencent.mm.opensdk.constants.ConstantsAPI;
import com.tencent.mm.opensdk.diffdev.DiffDevOAuthFactory;
import com.tencent.mm.opensdk.diffdev.IDiffDevOAuth;
import com.tencent.mm.opensdk.diffdev.OAuthErrCode;
@ -124,7 +128,7 @@ public class FakeWechatPlugin implements MethodCallHandler, PluginRegistry.ViewD
private static final String ARGUMENT_KEY_RESERVED = "reserved";
private static final String ARGUMENT_KEY_PARTNERID = "partnerId";
private static final String ARGUMENT_KEY_PREPAYID = "prepayId";
// private static final String ARGUMENT_KEY_NONCESTR = "noncestr";
// private static final String ARGUMENT_KEY_NONCESTR = "noncestr";
// private static final String ARGUMENT_KEY_TIMESTAMP = "timestamp";
private static final String ARGUMENT_KEY_PACKAGE = "package";
private static final String ARGUMENT_KEY_SIGN = "sign";
@ -151,6 +155,7 @@ public class FakeWechatPlugin implements MethodCallHandler, PluginRegistry.ViewD
private final AtomicBoolean register = new AtomicBoolean(false);
private IWXAPI iwxapi;
private BroadcastReceiver refreshWxappReceiver;
private FakeWechatPlugin(Registrar registrar, MethodChannel channel) {
this.registrar = registrar;
@ -187,7 +192,9 @@ public class FakeWechatPlugin implements MethodCallHandler, PluginRegistry.ViewD
private WechatReceiver wechatReceiver = new WechatReceiver() {
@Override
public void handleIntent(Intent intent) {
iwxapi.handleIntent(intent, iwxapiEventHandler);
if (iwxapi != null) {
iwxapi.handleIntent(intent, iwxapiEventHandler);
}
}
};
@ -242,10 +249,7 @@ public class FakeWechatPlugin implements MethodCallHandler, PluginRegistry.ViewD
@Override
public void onMethodCall(MethodCall call, Result result) {
if (METHOD_REGISTERAPP.equals(call.method)) {
String appId = call.argument(ARGUMENT_KEY_APPID);
iwxapi = WXAPIFactory.createWXAPI(registrar.context().getApplicationContext(), appId);
iwxapi.registerApp(appId);
result.success(null);
registerApp(call, result);
} else if (METHOD_ISWECHATINSTALLED.equals(call.method)) {
result.success(iwxapi.isWXAppInstalled());
} else if (METHOD_ISWECHATSUPPORTAPI.equals(call.method)) {
@ -285,6 +289,26 @@ public class FakeWechatPlugin implements MethodCallHandler, PluginRegistry.ViewD
}
}
private void registerApp(MethodCall call, Result result) {
final String appId = call.argument(ARGUMENT_KEY_APPID);
iwxapi = WXAPIFactory.createWXAPI(registrar.context().getApplicationContext(), appId);
iwxapi.registerApp(appId);
if (refreshWxappReceiver != null) {
registrar.context().unregisterReceiver(refreshWxappReceiver);
refreshWxappReceiver = null;
}
refreshWxappReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (iwxapi != null) {
iwxapi.registerApp(appId);
}
}
};
registrar.context().registerReceiver(refreshWxappReceiver, new IntentFilter(ConstantsAPI.ACTION_REFRESH_WXAPP));
result.success(null);
}
private void handleAuthCall(MethodCall call, Result result) {
SendAuth.Req req = new SendAuth.Req();
req.scope = call.argument(ARGUMENT_KEY_SCOPE);
@ -450,6 +474,10 @@ public class FakeWechatPlugin implements MethodCallHandler, PluginRegistry.ViewD
WechatReceiver.unregisterReceiver(registrar.context(), wechatReceiver);
}
qrauth.removeAllListeners();
if (refreshWxappReceiver != null) {
registrar.context().unregisterReceiver(refreshWxappReceiver);
refreshWxappReceiver = null;
}
return false;
}
}

View File

@ -34,7 +34,7 @@ android {
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "io.github.v7lin.fakewechatexample"
minSdkVersion 16
minSdkVersion 21
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName

View File

@ -16,7 +16,7 @@ dependencies:
image: ^2.0.7
path: ^1.6.2
fake_path_provider: ^0.0.1+1
fake_path_provider: ^0.1.2
fake_wechat:
path: ../

View File

@ -11,12 +11,12 @@ dependencies:
flutter:
sdk: flutter
meta: '>=1.1.6 <2.0.0'
meta: ^1.1.6
uuid: '>=1.0.0 <3.0.0'
convert: '>=2.0.2 <3.0.0'
crypto: '>=2.0.6 <3.0.0'
convert: ^2.0.2
crypto: ^2.0.6
jaguar_serializer: '>=2.2.12 <3.0.0'
jaguar_serializer: ^2.2.12
dev_dependencies:
flutter_test:
@ -27,7 +27,7 @@ dev_dependencies:
image: ^2.0.7
path: ^1.6.2
fake_path_provider: ^0.0.1+1
fake_path_provider: ^0.1.2
build_runner:
jaguar_serializer_cli: