C011摇钱树CMS免费开源小说APP系统带后端
1.适用范围
Java8
Kotlin:1.3.11
Gradle:3.1.2
Android Studio:3.2
2.集成准备
在配置CC阅读android客户端前,请先申请阿里热修复,友盟统计,新浪,QQ,微信等第三方平台的appkey,广告目前接入的是广点通广告,如需要,申请广点通广告位。如需推送功能,目前支持小米推送及华为推送,请申请相应功能。
阿里热修复 https://help.aliyun.com/product/51340.html
友盟统计 https://www.umeng.com
新浪微博 https://open.weibo.com/
QQ https://connect.qq.com/index.html
微信 https://open.weixin.qq.com/
广点通 https://e.qq.com/dev/index.html
小米推送 https://dev.mi.com/console/appservice/push.html
华为推送 https://developer.huawei.com/consumer/cn/service/hms/pushservice.html
支付宝 https://open.alipay.com/platform/home.htm
阿里短信 https://help.aliyun.com/product/44282.html
微信支付 https://pay.weixin.qq.com/index.php/core/home/login?return_url=%2F
3.配置文件
1.在Android Studio工程中的App模块中的SophixStubApplication文件中配置阿里热修复的相关信息:
@Override protected void attachBaseContext(Context base) { super.attachBaseContext(base); // 如果需要使用MultiDex,需要在此处调用。 MultiDex.install(this); initSophix(); } private void initSophix() { String appVersion = \\\\\\\\\\\\\\\"0.0.0\\\\\\\\\\\\\\\"; try { appVersion = this.getPackageManager() .getPackageInfo(this.getPackageName(), 0) .versionName; } catch (Exception e) {} final SophixManager instance = SophixManager.getInstance(); instance.setContext(this) .setAppVersion(appVersion) .setSecretMetaData(\\\\\\\\\\\\\\\"appkey\\\\\\\\\\\\\\\", \\\\\\\\\\\\\\\"appsecret\\\\\\\\\\\\\\\", \\\\\\\\\\\\\\\"appsecretToken\\\\\\\\\\\\\\\") .setEnableDebug(true) .setEnableFullLog() .setPatchLoadStatusStub(new PatchLoadStatusListener() { @Override public void onLoad(final int mode, final int code, final String info, final int handlePatchVersion) { if (code == PatchStatus.CODE_LOAD_SUCCESS) { Log.i(TAG, \\\\\\\\\\\\\\\"sophix load patch success!\\\\\\\\\\\\\\\"); } else if (code == PatchStatus.CODE_LOAD_RELAUNCH) { // 如果需要在后台重启,建议此处用SharePreference保存状态。 Log.i(TAG, \\\\\\\\\\\\\\\"sophix preload patch success. restart app to make effect.\\\\\\\\\\\\\\\"); } } }).initialize(); } 如不需要此功能,在AndroidManifest.xml中修改application的name为BookStoreApplication,并在BookStoreApplication类的onCreate方法中注释或删除SophixManager.getInstance().queryAndLoadNewPatch()
2.在Android Studio工程中的App模块中的BookStoreApplication文件中,配置友盟相关信息及三方信息,用于三方登录及分享功能:
UMConfigure.init(this, \\\\\\\\\\\\\\\"友盟key\\\\\\\\\\\\\\\",”渠道”, UMConfigure.DEVICE_TYPE_PHONE, \\\\\\\\\\\\\\\"\\\\\\\\\\\\\\\") setScenarioType(this, MobclickAgent.EScenarioType.E_UM_NORMAL) /** * 设置组件化的Log开关 * 参数: boolean 默认为false,如需查看LOG设置为true */ UMConfigure.setLogEnabled(BuildConfig.DEBUG_MODE) PlatformConfig.setWeixin(\\\\\\\\\\\\\\\"appkey\\\\\\\\\\\\\\\", \\\\\\\\\\\\\\\"appsecret\\\\\\\\\\\\\\\") PlatformConfig.setSinaWeibo(\\\\\\\\\\\\\\\"appkey\\\\\\\\\\\\\\\", \\\\\\\\\\\\\\\"appsecret\\\\\\\\\\\\\\\", \\\\\\\\\\\\\\\"授权回调地址\\\\\\\\\\\\\\\") PlatformConfig.setQQZone(\\\\\\\\\\\\\\\"appkey\\\\\\\\\\\\\\\", \\\\\\\\\\\\\\\"appsecret\\\\\\\\\\\\\\\") 注意QQ除了在这儿配置外,在AndroidManifest.xml中也需要配置 /** * 友盟-QQ */ <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=\\\\\\\\\\\\\\\"tencentAPPKEY\\\\\\\\\\\\\\\" /> </intent-filter> </activity> 在AndroidManifest.xml还需要配置友盟的渠道 /** * Channel ID用来标识App的推广渠道,作为推送消息时给用户分组的一个维度 */ <meta-data android:name=\\\\\\\\\\\\\\\"UMENG_CHANNEL\\\\\\\\\\\\\\\" android:value=\\\\\\\\\\\\\\\"${CHANNEL_VALUE}\\\\\\\\\\\\\\\" />
3.在Android Studio工程中的App模块中的BookStoreApplication文件中,配置推送相关功能。小米推送:
private fun initMiuiPush() { if (shouldInit()) { MiPushClient.registerPush(this, \\\\\\\\\\\\\\\"AppID\\\\\\\\\\\\\\\", \\\\\\\\\\\\\\\"AppKey\\\\\\\\\\\\\\\") } // 打开Log val newLogger = object : LoggerInterface { override fun setTag(tag: String) { // ignore } override fun log(content: String, t: Throwable) { Log.d(TAG, content, t) } override fun log(content: String) { Log.d(TAG, content) } } Logger.setLogger(this, newLogger) } 华为推送主要配置在AndroidManifest.xml中: /** * 华为推送 */ <meta-data android:name=\\\\\\\\\\\\\\\"com.huawei.hms.client.appid\\\\\\\\\\\\\\\" android:value=\\\\\\\\\\\\\\\"appid=******\\\\\\\\\\\\\\\" /> <meta-data android:name=\\\\\\\\\\\\\\\"com.huawei.hms.version\\\\\\\\\\\\\\\" android:value=\\\\\\\\\\\\\\\"2.6.1.301\\\\\\\\\\\\\\\" /> 华为推送接收到的数据为scheme类型,需要自信配置相应参数 /** * 接入HMSSDK 需要注册的应用下载服务 | Access HMSSDK need to register app download service */ <service android:name=\\\\\\\\\\\\\\\"com.huawei.updatesdk.service.deamon.download.DownloadService\\\\\\\\\\\\\\\" android:exported=\\\\\\\\\\\\\\\"false\\\\\\\\\\\\\\\" /> <activity android:name=\\\\\\\\\\\\\\\".book_push.HuaWeiReceiverActivity\\\\\\\\\\\\\\\"> <intent-filter> <action android:name=\\\\\\\\\\\\\\\"android.intent.action.VIEW\\\\\\\\\\\\\\\" /> <category android:name=\\\\\\\\\\\\\\\"android.intent.category.DEFAULT\\\\\\\\\\\\\\\" /> <data android:host=\\\\\\\\\\\\\\\"自定义域名\\\\\\\\\\\\\\\" android:path=\\\\\\\\\\\\\\\"/地址\\\\\\\\\\\\\\\" android:scheme=\\\\\\\\\\\\\\\"customscheme\\\\\\\\\\\\\\\" /> </intent-filter> </activity>
4.在CommenTag文件中,配置广点通广告:
const val AD_APPKEY = \\\\\\\\\\\\\\\"******\\\\\\\\\\\\\\\" // 开屏页广告位 const val AD_SPLASH_KEY = \\\\\\\\\\\\\\\"******\\\\\\\\\\\\\\\" //阅读页底部广告位 const val AD_BANNER_KEY = \\\\\\\\\\\\\\\"******\\\\\\\\\\\\\\\" //阅读页章节末尾广告位 const val AD_NATIVE_IMAGE = \\\\\\\\\\\\\\\"******\\\\\\\\\\\\\\\" //首页banner最后一页展示广告位 const val AD_NATIVE_BANNER_IMAGE = \\\\\\\\\\\\\\\"******\\\\\\\\\\\\\\\"
5.配置友盟统计多渠道,在config.gradle中定义渠道名称(示例中为渠道cc1/cc2/cc3/cc4)
channel = [ \\\\\\\\\\\\\\\"cc1\\\\\\\\\\\\\\\" : \\\\\\\\\\\\\\\'\\\\\\\\\\\\\\\"cc1\\\\\\\\\\\\\\\"\\\\\\\\\\\\\\\', \\\\\\\\\\\\\\\"cc2\\\\\\\\\\\\\\\" : \\\\\\\\\\\\\\\'\\\\\\\\\\\\\\\"cc2\\\\\\\\\\\\\\\"\\\\\\\\\\\\\\\', \\\\\\\\\\\\\\\"cc3\\\\\\\\\\\\\\\" : \\\\\\\\\\\\\\\'\\\\\\\\\\\\\\\"cc3\\\\\\\\\\\\\\\"\\\\\\\\\\\\\\\', \\\\\\\\\\\\\\\"cc4\\\\\\\\\\\\\\\" : \\\\\\\\\\\\\\\'\\\\\\\\\\\\\\\"cc4\\\\\\\\\\\\\\\"\\\\\\\\\\\\\\\', \\\\\\\\\\\\\\\"cc5\\\\\\\\\\\\\\\" : \\\\\\\\\\\\\\\'\\\\\\\\\\\\\\\"cc5\\\\\\\\\\\\\\\"\\\\\\\\\\\\\\\' ] 在app模块中的build.gradle中引用相应渠道同时,在readviewlibrary中的build.gradle中应用相应渠道 productFlavors { cc1 { manifestPlaceholders = [CHANNEL_VALUE:channel[\\\\\\\\\\\\\\\"cc1\\\\\\\\\\\\\\\"]] buildConfigField \\\\\\\\\\\\\\\"String\\\\\\\\\\\\\\\", \\\\\\\\\\\\\\\"DEBUG_CHANNEL\\\\\\\\\\\\\\\", channel[\\\\\\\\\\\\\\\"cc1\\\\\\\\\\\\\\\"] versionCode rootProject.ext.android_version.ccVersionCode versionName rootProject.ext.android_version.ccVersionName } cc2 { manifestPlaceholders = [CHANNEL_VALUE: channel[\\\\\\\\\\\\\\\"cc2\\\\\\\\\\\\\\\"]] buildConfigField \\\\\\\\\\\\\\\"String\\\\\\\\\\\\\\\", \\\\\\\\\\\\\\\"DEBUG_CHANNEL\\\\\\\\\\\\\\\", channel[\\\\\\\\\\\\\\\"cc2\\\\\\\\\\\\\\\"] versionCode rootProject.ext.android_version.ccVersionCode versionName rootProject.ext.android_version.ccVersionName } cc3 { manifestPlaceholders = [CHANNEL_VALUE: channel[\\\\\\\\\\\\\\\"cc3\\\\\\\\\\\\\\\"]] buildConfigField \\\\\\\\\\\\\\\"String\\\\\\\\\\\\\\\", \\\\\\\\\\\\\\\"DEBUG_CHANNEL\\\\\\\\\\\\\\\", channel[\\\\\\\\\\\\\\\"cc3\\\\\\\\\\\\\\\"] versionCode rootProject.ext.android_version.ccVersionCode versionName rootProject.ext.android_version.ccVersionName } cc4 { manifestPlaceholders = [CHANNEL_VALUE: channel[\\\\\\\\\\\\\\\"cc4\\\\\\\\\\\\\\\"]] buildConfigField \\\\\\\\\\\\\\\"String\\\\\\\\\\\\\\\", \\\\\\\\\\\\\\\"DEBUG_CHANNEL\\\\\\\\\\\\\\\", channel[\\\\\\\\\\\\\\\"cc4\\\\\\\\\\\\\\\"] versionCode rootProject.ext.android_version.ccVersionCode versionName rootProject.ext.android_version.ccVersionName } } productFlavors { cc1 { buildConfigField \\\\\\\\\\\\\\\"String\\\\\\\\\\\\\\\", \\\\\\\\\\\\\\\"DEBUG_CHANNEL\\\\\\\\\\\\\\\", rootProject.ext.channel[\\\\\\\\\\\\\\\"cc1\\\\\\\\\\\\\\\"] } cc2 { buildConfigField \\\\\\\\\\\\\\\"String\\\\\\\\\\\\\\\", \\\\\\\\\\\\\\\"DEBUG_CHANNEL\\\\\\\\\\\\\\\", rootProject.ext.channel[\\\\\\\\\\\\\\\"cc2\\\\\\\\\\\\\\\"] } cc3 { buildConfigField \\\\\\\\\\\\\\\"String\\\\\\\\\\\\\\\", \\\\\\\\\\\\\\\"DEBUG_CHANNEL\\\\\\\\\\\\\\\", rootProject.ext.channel[\\\\\\\\\\\\\\\"cc3\\\\\\\\\\\\\\\"] } cc4 { buildConfigField \\\\\\\\\\\\\\\"String\\\\\\\\\\\\\\\", \\\\\\\\\\\\\\\"DEBUG_CHANNEL\\\\\\\\\\\\\\\", rootProject.ext.channel[\\\\\\\\\\\\\\\"cc4\\\\\\\\\\\\\\\"] } } 6.微信支付配置,注意微信登录及微信支付结果回调类WXEntryActivity和WXPayEntryActivity是在包名文件夹下的wxapi中,属于最外层的一级文件夹。
7.关于友盟配置签名文件,在app模块下的build.gradle中配置应用的签名文件
signingConfigs { debug { toreFile file(\\\\\\\\\\\\\\\'jks文件地址\\\\\\\\\\\\\\\') storePassword \\\\\\\\\\\\\\\"*********\\\\\\\\\\\\\\\" keyAlias \\\\\\\\\\\\\\\"*****\\\\\\\\\\\\\\\" keyPassword \\\\\\\\\\\\\\\"*********\\\\\\\\\\\\\\\" } release { storeFile file(\\\\\\\\\\\\\\\'jks文件地址\\\\\\\\\\\\\\\') storePassword \\\\\\\\\\\\\\\"*******\\\\\\\\\\\\\\\" keyAlias \\\\\\\\\\\\\\\"*****\\\\\\\\\\\\\\\" keyPassword \\\\\\\\\\\\\\\"**********\\\\\\\\\\\\\\\" } }