Skip to content

Commit

Permalink
升级sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
like5188 committed Feb 24, 2022
1 parent aea7590 commit 95aa56e
Show file tree
Hide file tree
Showing 16 changed files with 119 additions and 214 deletions.
31 changes: 14 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,44 +25,41 @@
```groovy
dependencies {
implementation 'com.github.like5188:WxPay:版本号'
// 引用LiveDataBus库,用于接收返回结果
implementation 'com.github.like5188.LiveDataBus:livedatabus:1.2.2'
kapt 'com.github.like5188.LiveDataBus:livedatabus_compiler:1.2.2'
// 引用 FlowEventBus 库,用于接收返回结果
implementation 'com.github.like5188.FlowEventBus:floweventbus:0.0.3'
implementation 'com.github.like5188.FlowEventBus:floweventbus_annotations:0.0.3'
kapt 'com.github.like5188.FlowEventBus:floweventbus_compiler:0.0.3'
implementation("org.jetbrains.kotlin:kotlin-reflect:1.6.10")
}
```

2、在Application中进行一次初始化。
```java
WXPayUtils.getInstance(this).init(appid)
WXPayUtils.init(context, appid)
```

3、支付
```java
WXPayUtils.getInstance(this).pay(payParams)
WXPayUtils.pay(context, payParams)
```

4、接收返回结果
```java
在任意一个类中注册
LiveDataBus.register(this, this);
FlowEventBus.register(this)
```
然后用下面三个方法接收支付宝返回的结果
```java
// 支付成功
@RxBusSubscribe(WXPayUtils.TAG_PAY_SUCCESS)
public void onPaySuccess() {
@BusObserver([WxPayUtils.TAG_PAY_SUCCESS])
fun onPaySuccess() {
Toast.makeText(this, "微信支付成功", Toast.LENGTH_SHORT).show()
}
```
```java
// 支付失败
@RxBusSubscribe(WXPayUtils.TAG_PAY_FAILURE)
public void onPayFailure() {
@BusObserver([WxPayUtils.TAG_PAY_FAILURE])
fun onPayFailure() {
Toast.makeText(this, "微信支付失败", Toast.LENGTH_SHORT).show()
}
```

5、Proguard
```java
# LiveDataBus
-keep class * extends com.like.livedatabus.Bridge
-keep class com.like.livedatabus_annotations.**{*;}
```
5 changes: 2 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.3.10'
ext.kotlin_version = '1.6.10'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.android.tools.build:gradle:7.1.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
34 changes: 0 additions & 34 deletions gradle-mvn-push.gradle

This file was deleted.

12 changes: 8 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
# Project-wide Gradle settings.

# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.

# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx1536m

# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
# AndroidX package structure to make it clearer which packages are bundled with the
# Android operating system, and which are packaged with your app's APK
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true
# Kotlin code style for this project: "official" or "obsolete":
kotlin.code.style=official
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Fri May 19 10:10:46 CST 2017
#Thu May 18 16:21:15 CST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.7-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
34 changes: 20 additions & 14 deletions sample/build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'

android {
compileSdkVersion 28
compileSdkVersion 31

defaultConfig {
applicationId "com.like.wxpay.sample"
minSdkVersion 19
targetSdkVersion 28
minSdkVersion 23
targetSdkVersion 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
Expand All @@ -36,14 +35,17 @@ android {
shrinkResources false
debuggable true
signingConfig signingConfigs.debug
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
resValue "string", "app_name", "微信支付-debug"
}
release {
minifyEnabled true
zipAlignEnabled true
shrinkResources true
debuggable true
signingConfig signingConfigs.release
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
resValue "string", "app_name", "微信支付"
}
}

Expand All @@ -54,14 +56,18 @@ android {
}

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

implementation 'com.github.like5188.FlowEventBus:floweventbus:0.0.3'
implementation 'com.github.like5188.FlowEventBus:floweventbus_annotations:0.0.3'
kapt 'com.github.like5188.FlowEventBus:floweventbus_compiler:0.0.3'
implementation("org.jetbrains.kotlin:kotlin-reflect:1.6.10")

implementation 'com.github.like5188.LiveDataBus:livedatabus:1.2.2'
kapt 'com.github.like5188.LiveDataBus:livedatabus_compiler:1.2.2'
implementation project(':wxpay')
}
6 changes: 1 addition & 5 deletions sample/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,4 @@

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

# LiveDataBus
-keep class * extends com.like.livedatabus.Bridge
-keep class com.like.livedatabus_annotations.**{*;}
#-renamesourcefileattribute SourceFile
4 changes: 3 additions & 1 deletion sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
android:supportsRtl="true"
android:theme="@style/AppTheme">

<activity android:name=".MainActivity">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
23 changes: 20 additions & 3 deletions sample/src/main/java/com/like/wxpay/sample/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,18 +1,35 @@
package com.like.wxpay.sample

import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.view.View
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.like.floweventbus.FlowEventBus
import com.like.floweventbus_annotations.BusObserver
import com.like.wxpay.WxPayUtils

class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
WxPayUtils.getInstance(this).init("wxb4ba3c02aa476ea1")
WxPayUtils.init(this, "wxb4ba3c02aa476ea1")
FlowEventBus.register(this)
}

fun pay(view: View) {
WxPayUtils.getInstance(this).pay("{\"appid\":\"wxb4ba3c02aa476ea1\",\"partnerid\":\"1900006771\",\"package\":\"Sign=WXPay\",\"noncestr\":\"ffd8363d5149de96acfb21f861b6f2d7\",\"timestamp\":1546589467,\"prepayid\":\"wx04161107414587fcf981bea61635925982\",\"sign\":\"3618C1D08BC50D94F2952C3C3A7F7B3B\"}")
WxPayUtils.pay(
this,
"{\"appid\":\"wxb4ba3c02aa476ea1\",\"partnerid\":\"1900006771\",\"package\":\"Sign=WXPay\",\"noncestr\":\"ffd8363d5149de96acfb21f861b6f2d7\",\"timestamp\":1546589467,\"prepayid\":\"wx04161107414587fcf981bea61635925982\",\"sign\":\"3618C1D08BC50D94F2952C3C3A7F7B3B\"}"
)
}

@BusObserver([WxPayUtils.TAG_PAY_SUCCESS])
fun onPaySuccess() {
Toast.makeText(this, "微信支付成功", Toast.LENGTH_SHORT).show()
}

@BusObserver([WxPayUtils.TAG_PAY_FAILURE])
fun onPayFailure() {
Toast.makeText(this, "微信支付失败", Toast.LENGTH_SHORT).show()
}
}
1 change: 0 additions & 1 deletion sample/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
<resources>
<string name="app_name">WxPay</string>
</resources>
4 changes: 3 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
include ':sample', ':wxpay'
rootProject.name='WxPay'
include ':sample'
include ':wxpay'
31 changes: 15 additions & 16 deletions wxpay/build.gradle
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'

android {
compileSdkVersion 28
compileSdkVersion 31

defaultConfig {
minSdkVersion 19
targetSdkVersion 28
minSdkVersion 23
targetSdkVersion 31
versionCode 1
versionName "1.0"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'proguard-rules.pro'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
dataBinding {
Expand All @@ -26,15 +26,14 @@ android {
}

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
compileOnly 'com.android.support:appcompat-v7:28.0.0'
compileOnly "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

compileOnly 'com.github.like5188.LiveDataBus:livedatabus:1.2.2'
implementation 'com.github.like5188.FlowEventBus:floweventbus:0.0.3'
implementation 'com.tencent.mm.opensdk:wechat-sdk-android-without-mta:+'
}

apply from: rootProject.file('./gradle-mvn-push.gradle')
28 changes: 0 additions & 28 deletions wxpay/src/main/java/com/like/wxpay/ApiFactory.kt

This file was deleted.

Loading

0 comments on commit 95aa56e

Please sign in to comment.