效果图
源码
版本
集成
-
添加仓库地址
maven { url "https://dl.bintray.com/thelasterstar/maven/" } // 微博 aar maven { url 'http://developer.huawei.com/repo/' } // 华为仓库 maven { url 'https://dl.bintray.com/wenjie/maven' }
-
根据要集成的第三方库添加依赖
api 'com.enowr.android:Auth:0.0.7' api 'com.enowr.android:AuthHW:0.0.7' api 'com.enowr.android:AuthQQ:0.0.7' api 'com.enowr.android:AuthWB:0.0.7' api 'com.enowr.android:AuthWX:0.0.7' api 'com.enowr.android:AuthYL:0.0.7' api 'com.enowr.android:AuthZFB:0.0.7' api 'com.enowr.android:AuthOPPO:0.0.7'
-
Manifest
<manifest> <!-- 华为权限 --> <uses-permission android:name="android.permission.INTERNET" /> <!--HMS-SDK引导升级HMS功能,访问OTA服务器需要网络权限--> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <!--HMS-SDK引导升级HMS功能,保存下载的升级包需要SD卡写权限--> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <!--检测网络状态--> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> <!--检测wifi状态--> <uses-permission android:name="android.permission.READ_PHONE_STATE"/> <!--为了获取用户手机的IMEI,用来唯一的标识用户。--> <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" /> <!--如果是安卓8.0,应用编译配置的targetSdkVersion>=26,请务必添加权限 --> <!-- QQ权限 --> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <!-- SDK2.1新增获取用户位置信息 --> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" /> <uses-permission android:name="android.permission.CHANGE_WIFI_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.INTERNET" /> <uses-permission android:name="android.permission.READ_PHONE_STATE" /><!-- 用于调用 JNI --> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <!-- 微信权限 其中网络权限如果没有使用扫码登录功能非必要;后三个权限,如果没有使用mta,也非必要,即使有使用mta,去掉也不影响功能 --> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> <uses-permission android:name="android.permission.READ_PHONE_STATE"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <!-- 银联 --> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_PHONE_STATE" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.NFC" /> <uses-permission android:name="org.simalliance.openmobileapi.SMARTCARD" /> <uses-feature android:name="android.hardware.nfc.hce" /> <!-- 支付宝 --> <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" /> <!-- OPPO --> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" /> <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" /> <uses-permission android:name="android.permission.READ_PHONE_STATE" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.GET_TASKS" /> <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" /> <uses-permission android:name="android.permission.GET_ACCOUNTS" /> <uses-permission android:name="android.permission.USE_CREDENTIALS" /> <uses-permission android:name="android.permission.SEND_SMS" /> <uses-permission android:name="android.permission.READ_SMS" /> <uses-permission android:name="android.permission.WRITE_SMS" /> <uses-permission android:name="android.permission.RECEIVE_SMS" /> <application> <!-- 华为 --> <!-- value的值“xxx”用实际申请的应用ID替换,来源于开发者联盟网站应用的服务详情。--> <!-- replace 用于避免其他库引用华为sdk时设置 appId 冲突 --> <meta-data tools:replace="android:value" android:name="com.huawei.hms.client.appid" android:value="appid=xxx"> </meta-data> <!-- 在application节点下增加provider,UpdateProvider用于HMS-SDK引导升级HMS,提供给系统安装器读取升级文件。UpdateSdkFileProvider用于应用自升级。--> <!--“xxx.xxx.xxx”用实际的应用包名替换--> <provider android:name="com.huawei.hms.update.provider.UpdateProvider" android:authorities="xxx.xxx.xxx.hms.update.provider" android:exported="false" android:grantUriPermissions="true" > </provider> <!-- 如果应用使用了HMSAgent.checkUpdate(Activity activity,CheckUpdateHandler callback)接口,则必须配置UpdateSdkFileProvider --> <!--“xxx.xxx.xxx”用实际的应用包名替换--> <provider android:name="com.huawei.updatesdk.fileprovider.UpdateSdkFileProvider" android:authorities="xxx.xxx.xxx.updateSdk.fileProvider" android:exported="false" android:grantUriPermissions="true"> </provider> <!-- QQ --> <!-- xxxxxx 用注册的appId替换 --> <activity android:name="com.tencent.tauth.AuthActivity" android:launchMode="singleTask" android:noHistory="true"> <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:scheme="tencentxxxxxx" /> </intent-filter> </activity> <!-- 微信 分享登录实现 WXEntryActivity 继承自 AuthActivity, 支付实现 WXPayEntryActivity 继承自 AuthActivity --> <activity android:name=".wxapi.WXEntryActivity" android:exported="true" android:label="@string/app_name" android:launchMode="singleTask" android:taskAffinity="net.sourceforge.simcpux" android:theme="@android:style/Theme.Translucent.NoTitleBar" /> <activity android:name=".wxapi.WXPayEntryActivity" android:exported="true" android:launchMode="singleTask" android:theme="@android:style/Theme.Translucent.NoTitleBar" /> <!-- 支付宝签约 支付宝免密支付完成时走此filter,必须匹配scheme --> <activity android:name="com.enowr.auth.AliRouseActivity" android:allowTaskReparenting="true"> <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:scheme="xxx" /> </intent-filter> </activity> <!-- OPPO --> <meta-data android:name="debug_mode" android:value="false" /> <!-- 日志开关,发布时候设置为false --> <meta-data android:name="app_key" android:value="c5217trjnrmU6gO5jG8VvUFU0" /> <!-- appKey --> </application> </manifest>
-
混淆
# Auth -keep class com.enowr.** {*;} # 华为 -ignorewarning -keepattributes *Annotation* -keepattributes Exceptions -keepattributes InnerClasses -keepattributes Signature -keepattributes SourceFile,LineNumberTable -keep class com.hianalytics.android.**{*;} -keep class com.huawei.updatesdk.**{*;} -keep class com.huawei.hms.**{*;} -keep class com.huawei.android.hms.agent.**{*;} # QQ -keep class com.tencent.open.TDialog$* -keep class com.tencent.open.TDialog$* {*;} -keep class com.tencent.open.PKDialog -keep class com.tencent.open.PKDialog {*;} -keep class com.tencent.open.PKDialog$* -keep class com.tencent.open.PKDialog$* {*;} # 微博 -keep class com.sina.weibo.sdk.** {*;} # 微信 -keep class com.tencent.mm.opensdk.** {*;} -keep class com.tencent.wxop.** {*;} -keep class com.tencent.mm.sdk.** {*;} # 银联 -keep public class com.unionpay.uppay.net.HttpConnection {public <methods>;} -keep public class com.unionpay.uppay.net.HttpParameters {public <methods>;} -keep public class com.unionpay.uppay.model.BankCardInfo {public <methods>;} -keep public class com.unionpay.uppay.model.PAAInfo {public <methods>;} -keep public class com.unionpay.uppay.model.ResponseInfo {public <methods>;} -keep public class com.unionpay.uppay.model.PurchaseInfo {public <methods>;} -keep public class com.unionpay.uppay.util.DeviceInfo {public <methods>;} -keep public class com.unionpay.uppay.util.PayEngine { public <methods>; native <methods>; } -keep public class com.unionpay.utils.UPUtils {native <methods>;} # 支付宝 -keep class com.alipay.android.app.IAlixPay{*;} -keep class com.alipay.android.app.IAlixPay$Stub{*;} -keep class com.alipay.android.app.IRemoteServiceCallback{*;} -keep class com.alipay.android.app.IRemoteServiceCallback$Stub{*;} -keep class com.alipay.sdk.app.PayTask{ public *;} -keep class com.alipay.sdk.app.AuthTask{ public *;} -keep class com.alipay.sdk.app.H5PayCallback { <fields>; <methods>; } -keep class com.alipay.android.phone.mrpc.core.** { *; } -keep class com.alipay.apmobilesecuritysdk.** { *; } -keep class com.alipay.mobile.framework.service.annotation.** { *; } -keep class com.alipay.mobilesecuritysdk.face.** { *; } -keep class com.alipay.tscenter.biz.rpc.** { *; } -keep class org.json.alipay.** { *; } -keep class com.alipay.tscenter.** { *; } -keep class com.ta.utdid2.** { *;} -keep class com.ut.device.** { *;} # SDK 包可能不包含 utdid -dontwarn com.ta.utdid2.** -dontwarn com.ut.device.** # SDK 包可能不包含 securitysdk -dontwarn com.alipay.mobilesecuritysdk.** # OPPO -keep class com.nearme.** {*;}
-
初始化
Auth.init() .setHWAppID("") .setHWKey("") .setHWMerchantID("") .setQQAppID("") .setWXAppID("") .setWXSecret("") .setWBAppKey("") .setWBRedirectUrl("") .setWBScope("") .setOPPOAppSecret("secret") .build(); // 如果使用华为支付功能, 还需要在 MainActivity 里初始化华为 Auth.withHW(context).initHW(activity); // OPPO 要求使用OPPO 自带的退出功能 Auth.withOPPO(context).exit(activity); // 使用微信相关功能 // 包名相应目录下新建一个wxapi目录,并在该wxapi目录下新增两个WXPayEntryActivity、WXEntryActivity类,继承自AuthActivity
使用
public void hwLogin() {
Auth.withHW(this)
.loginForceLogin(false) // 当force为false时,错误码为2001、2002时,会再次以参数为ture尝试调用一次
.login(mCallback);
}
public void hwPay() {
Auth.withHW(this)
.payAmount("")
.payApplicationId("")
.payChannel(1)
.payCountry("")
.payCurrency("")
.payExtReserved("")
.payMerchantId("")
.payMerchantName("")
.payProductDesc("")
.payProductName("")
.payPublicKey("")
.payRequestId("")
.payServiceCatalog("")
.paySign("")
.payUrl("")
.payVersion("")
.pay(mCallback);
}
public void hwRouse() {
Auth.withHW(this)
.rouseAmount("")
.rouseApplicationId("")
.rouseChannel(1)
.rouseCountry("")
.rouseCurrency("")
.rouseExtReserved("")
.rouseMerchantId("")
.rouseMerchantName("")
.rouseProductDesc("")
.rouseProductName("")
.rousePublicKey("")
.rouseRequestId("")
.rouseServiceCatalog("")
.rouseSign("")
.rouseUrl("")
.rouseVersion("")
.rouseTradeType("")
.rouse(mCallback);
}
public void oppoPay() {
Auth.withOPPO(this)
.payAmount(1)
.payAttach("attach")
.payOrderId(String.valueOf(System.currentTimeMillis()))
.payProductName("test")
.payProductDesc("test")
.payCallbackUrl("")
.payUseCachedChannel(false)
.pay(mCallback);
}
public void qqLogin() {
Auth.withQQ(this)
.loginQrcode(true)
.login(mCallback);
}
public void qqShareText() {
Auth.withQQ(this)
.shareTextArk("")
.shareTextImage("")
.shareTextName("")
.shareTextQzoneHide(true)
.shareTextSummary("")
.shareTextTargetUrl("")
.shareTextTitle("")
.shareText(mCallback);
}
public void qqShareImage() {
Auth.withQQ(this)
.shareImageArk("")
.shareImagePath("")
.shareImageName("")
.shareImageQzoneHide(true)
.shareImage(mCallback);
}
public void qqShareMusic() {
Auth.withQQ(this)
.shareMusicImageUrl("")
.shareMusicSummary("")
.shareMusicArk("")
.shareMusicName("")
.shareMusicQzoneHide(true)
.shareMusicTargetUrl("")
.shareMusicTitle("")
.shareMusicUrl("")
.shareMusic(mCallback);
}
public void qqShareVideo() {
Auth.withQQ(this)
.shareVideoPath("")
.shareVideoBack("")
.shareVideoImageList(null)
.shareVideoScene("")
.shareVideoSummary("")
.shareVideo(mCallback);
}
public void qqShareApp() {
Auth.withQQ(this)
.shareAppName("")
.shareAppImageUrl("")
.shareAppSummary("")
.shareAppTitle("")
.shareAppArk("")
.shareAppQzoneHide(true)
.shareApp(mCallback);
}
public void qqShareQzone() {
Auth.withQQ(this)
.shareToQzoneImageList(null)
.shareToQzoneSummary("")
.shareToQzoneTargetUrl("")
.shareToQzoneTitle("")
.shareToQzone(mCallback);
}
public void qqShareMood() {
Auth.withQQ(this)
.shareToMoodBack("")
.shareToMoodImageList(null)
.shareToMoodScene("")
.shareToMoodSummary("")
.shareToMoodVideoPath("")
.shareToMood(mCallback);
}
public void wbLogin() {
Auth.withWB(this)
.login(mCallback);
}
public void wbShareText() {
Auth.withWB(this)
.shareTextContent("")
.shareTextSummary("")
.shareTextTitle("")
.shareTextUrl("")
.shareText(mCallback);
}
public void wbShareImage() {
Auth.withWB(this)
.shareImageBitmap(null)
.shareImageContent("")
.shareImage(mCallback);
}
public void wbShareMultiImage() {
Auth.withWB(this)
.shareMultiImageContent("")
.shareMultiImageUriList(null)
.shareMultiImage(mCallback);
}
public void wbShareLink() {
Auth.withWB(this)
.shareLinkContent("")
.shareLinkSummary("")
.shareLinkThumbImage(null)
.shareLinkTitle("")
.shareLinkUrl("")
.shareLink(mCallback);
}
public void wbShareVideo() {
Auth.withWB(this)
.shareVideoPath("")
.shareVideoContent("")
.shareVideoSummary("")
.shareVideoTitle("")
.shareVideo(mCallback);
}
public void wbShareToStory() {
Auth.withWB(this)
.shareToStoryImagePath("")
.shareToStoryVideoPath("")
.shareToStory(mCallback);
}
public void wxLogin() {
Auth.withWX(this)
.login(mCallback);
}
public void wxPay() {
Auth.withWX(this)
.payNonceStr("")
.payPackageValue("")
.payPartnerId("")
.payPrepayId("")
.paySign("")
.payTimestamp("")
.pay(mCallback);
}
public void wxRouse() {
Auth.withWX(this)
.rouseUrl("")
.rouse(mCallback);
}
public void wxShareText() {
Auth.withWX(this)
.shareTextSummary("")
.shareTextContent("")
.shareTextThumbData(null)
.shareTextTitle("")
.shareText(mCallback);
}
public void wxShareImage() {
Auth.withWX(this)
.shareImageBitmap(null)
.shareImageSummary("")
.shareImageThumbData(null)
.shareImageTitle("")
.shareImage(mCallback);
}
public void wxShareLink() {
Auth.withWX(this)
.shareLinkThumbData(null)
.shareLinkSummary("")
.shareLinkTitle("")
.shareLinkUrl("")
.shareLink(mCallback);
}
public void wxShareVideo() {
Auth.withWX(this)
.shareVideoThumbData(null)
.shareVideoSummary("")
.shareVideoLowBandUrl("")
.shareVideoTitle("")
.shareVideoUrl("")
.shareVideo(mCallback);
}
public void wxShareMusic() {
Auth.withWX(this)
.shareMusicThumbData(null)
.shareMusicSummary("")
.shareMusicDataUrl("")
.shareMusicLowBandDataUrl("")
.shareMusicLowBandUrl("")
.shareMusicTitle("")
.shareMusicUrl("")
.shareMusic(mCallback);
}
public void wxShareApp() {
Auth.withWX(this)
.shareAppId("")
.shareAppPath("")
.shareAppSummary("")
.shareAppThumbData(null)
.shareAppTitle("")
.shareAppType(1)
.shareAppUrl("")
.shareAppWithShareTicket(true)
.shareApp(mCallback);
}
public void ylPay() {
Auth.withYL(this)
.payOrderInfo("")
.payIsTest(true)
.pay(mCallback);
}
public void zfbPay() {
Auth.withZFB(this)
.payOrderInfo("")
.payIsShowLoading(true)
.pay(mCallback);
}
public void zfbRouse() {
Auth.withZFB(this)
.rouseUrl("")
.rouse(mCallback);
}
返回码
-
QQ
110201:未登陆 110405:登录请求被限制 110404:请求参数缺少appid 110401:请求的应用不存在 110407:应用已经下架 110406:应用没有通过审核 100044:错误的sign 110500:获取用户授权信息失败 110501:获取应用的授权信息失败 110502:设置用户授权失败 110503:获取token失败 110504:系统内部错误
-
微博
C8998: 签名不一致 8000: 没有安装客户端 8001: 非官方客户端
OPPO 为离线文档
说明
-
华为:Mac 下集成Agent执行脚本文件没反应。
GetHMSAgent_cn.sh 换行符的原因导致在macos下执行无反映,可通过下列命令替换下换行符:
cat GetHMSAgent_cn.sh | tr "^M" "\n" > GetHMSAgent_cn_new.sh -
华为:同时引入其他第三方华为支持时(如极光的华为推送插件)
禁用华为依赖传递,由于极光插件全量引入了华为SDK,所以全部禁用所有依赖
implementation ('com.enowr.android:AuthHW:0.0.3'){transitive false}
引入极光的华为插件,配置相关配置即可
implementation 'cn.jiguang.sdk.plugin:huawei:3.3.2'