Skip to content

Commit 432b233

Browse files
committed
升级支付功能,修复内存泄漏
1 parent ab13524 commit 432b233

File tree

8 files changed

+52
-60
lines changed

8 files changed

+52
-60
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
annotationProcessor 'com.jakewharton:butterknife-compiler:10.1.0'
1515

1616
// 支付模块
17-
implementation 'com.sdwfqin.quicklib:paylib:3.0.2'
17+
implementation 'com.sdwfqin.quicklib:paylib:3.1.0'
1818

1919
// Android 图片加载库(Glide封装)
2020
implementation 'com.sdwfqin.quick:imageloader:3.0.2'
@@ -32,7 +32,7 @@
3232
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
3333

3434
// 支付模块
35-
implementation 'com.sdwfqin.quicklib:paylib:1.0.5'
35+
implementation 'com.sdwfqin.quicklib:paylib:1.1.1'
3636

3737
// Android 图片加载库(Glide封装)
3838
implementation 'com.sdwfqin.quick:imageloader:2.0.2'

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ buildscript {
77
jcenter()
88
}
99
dependencies {
10-
classpath 'com.android.tools.build:gradle:3.5.0'
10+
classpath 'com.android.tools.build:gradle:3.5.1'
1111
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
1212
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
1313
// classpath "com.tencent.bugly:tinker-support:1.1.5"

paylib/README.md

Lines changed: 0 additions & 37 deletions
This file was deleted.

paylib/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apply plugin: 'com.android.library'
22

33
// gradlew pay:clean pay:build pay:bintrayUpload
44

5-
version = "3.0.2"
5+
version = "3.1.0"
66

77
android {
88
compileSdkVersion rootProject.ext.android.compileSdkVersion
@@ -11,7 +11,7 @@ android {
1111
defaultConfig {
1212
minSdkVersion rootProject.ext.android.minSdkVersion
1313
targetSdkVersion rootProject.ext.android.targetSdkVersion
14-
versionCode 10
14+
versionCode 31
1515
versionName version
1616
}
1717

paylib/src/main/java/com/sdwfqin/paylib/alipay/AliPayTools.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,15 @@ public void handleMessage(Message msg) {
3737
// 同步返回需要验证的信息
3838
String resultInfo = payResult.getResult();
3939
String resultStatus = payResult.getResultStatus();
40+
String memo = payResult.getMemo();
4041
// 判断resultStatus 为9000则代表支付成功
41-
if (TextUtils.equals(resultStatus, "9000")) {
42-
sOnRequestListener.onSuccess(resultStatus);
43-
} else {
44-
// 该笔订单真实的支付结果,需要依赖服务端的异步通知。
45-
sOnRequestListener.onError(resultStatus);
42+
int status = 0;
43+
try {
44+
status = Integer.parseInt(resultStatus);
45+
} catch (NumberFormatException e) {
46+
status = -1;
4647
}
48+
sOnRequestListener.onCallback(status, memo);
4749
break;
4850
}
4951
default:
@@ -110,4 +112,10 @@ public static void aliPay(final Activity activity, String orderInfo, OnRequestLi
110112
payThread.start();
111113
}
112114

115+
/**
116+
* 销毁
117+
*/
118+
public static void detach() {
119+
sOnRequestListener = null;
120+
}
113121
}

paylib/src/main/java/com/sdwfqin/paylib/interfaces/OnRequestListener.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
* @date 2018/1/25
88
*/
99
public interface OnRequestListener {
10-
void onSuccess(String s);
1110

12-
void onError(String s);
11+
void onCallback(int code, String msg);
1312
}

paylib/src/main/java/com/sdwfqin/paylib/wechat/WechatPay.java

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
*/
2424
public class WechatPay {
2525

26+
/**
27+
* 未安装微信或微信版本过低
28+
*/
29+
public static final int SUCCESS_PAY = 0;
2630
/**
2731
* 未安装微信或微信版本过低
2832
*/
@@ -35,8 +39,16 @@ public class WechatPay {
3539
* 支付失败
3640
*/
3741
public static final int ERROR_PAY = 3;
42+
/**
43+
* 支付取消
44+
*/
45+
public static final int CANCEL_PAY = 4;
46+
/**
47+
* 统一下单网络异常
48+
*/
49+
public static final int WX_NETWORK_ERROR = 5;
3850

39-
private static WechatPay sMWechatPay;
51+
private static WechatPay sWechatPay;
4052
private IWXAPI mWXApi;
4153
private String mPayParam;
4254
private WechatPayResultCallBack mCallback;
@@ -47,13 +59,13 @@ public WechatPay(Context context, String wxAppid) {
4759
}
4860

4961
public static void init(Context context, String wxAppid) {
50-
if (sMWechatPay == null) {
51-
sMWechatPay = new WechatPay(context, wxAppid);
62+
if (sWechatPay == null) {
63+
sWechatPay = new WechatPay(context, wxAppid);
5264
}
5365
}
5466

5567
public static WechatPay getInstance() {
56-
return sMWechatPay;
68+
return sWechatPay;
5769
}
5870

5971
public IWXAPI getWXApi() {
@@ -160,4 +172,14 @@ public interface WechatPayResultCallBack {
160172
*/
161173
void onCancel();
162174
}
175+
176+
/**
177+
* 销毁方法
178+
*/
179+
public static void detach(){
180+
if (sWechatPay != null){
181+
sWechatPay.getWXApi().detach();
182+
}
183+
sWechatPay = null;
184+
}
163185
}

paylib/src/main/java/com/sdwfqin/paylib/wechat/WechatPayTools.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public static void wechatPayUnifyOrder(final Context mContext, final String appi
104104
call.enqueue(new Callback() {
105105
@Override
106106
public void onFailure(Call call, IOException e) {
107-
onRequestListener.onError(e.getMessage());
107+
onRequestListener.onCallback(WechatPay.WX_NETWORK_ERROR, e.getMessage());
108108
}
109109

110110
@Override
@@ -130,7 +130,7 @@ public void onResponse(Call call, Response response) throws IOException {
130130

131131
wechatPayApp(mContext, appid, mchId, wxPrivateKey, sortedMap, onRequestListener);
132132
} catch (IOException e) {
133-
onRequestListener.onError(e.getMessage());
133+
onRequestListener.onCallback(WechatPay.WX_NETWORK_ERROR, e.getMessage());
134134
}
135135
}
136136
});
@@ -225,30 +225,30 @@ public static void doWXPay(Context mContext, String wxAppid, String payParam, fi
225225
WechatPay.getInstance().doPay(payParam, new WechatPay.WechatPayResultCallBack() {
226226
@Override
227227
public void onSuccess() {
228-
onRequestListener.onSuccess("微信支付成功");
228+
onRequestListener.onCallback(WechatPay.SUCCESS_PAY, "微信支付成功");
229229
}
230230

231231
@Override
232232
public void onError(int errorCode) {
233233
switch (errorCode) {
234234
case WechatPay.NO_OR_LOW_WX:
235-
onRequestListener.onError("未安装微信或微信版本过低");
235+
onRequestListener.onCallback(WechatPay.NO_OR_LOW_WX, "未安装微信或微信版本过低");
236236
break;
237237

238238
case WechatPay.ERROR_PAY_PARAM:
239-
onRequestListener.onError("参数错误");
239+
onRequestListener.onCallback(WechatPay.ERROR_PAY_PARAM, "参数错误");
240240
break;
241241

242242
case WechatPay.ERROR_PAY:
243-
onRequestListener.onError("支付失败");
243+
onRequestListener.onCallback(WechatPay.ERROR_PAY, "支付失败");
244244
break;
245245
default:
246246
}
247247
}
248248

249249
@Override
250250
public void onCancel() {
251-
onRequestListener.onError("支付取消");
251+
onRequestListener.onCallback(WechatPay.CANCEL_PAY, "支付取消");
252252
}
253253
});
254254
}

0 commit comments

Comments
 (0)