From d4bb277776435d3655626112a9c44049649f9875 Mon Sep 17 00:00:00 2001 From: zhangqin <1245366907@qq.com> Date: Fri, 2 Mar 2018 16:39:50 +0800 Subject: [PATCH] fix wechat --- ReadMe.md | 28 +++++++++-- app/src/main/AndroidManifest.xml | 4 ++ .../quickseed/wxapi/WXPayEntryActivity.java | 47 +++++++++++++++++++ app/src/main/res/layout/pay_result.xml | 4 ++ quicklib/build.gradle | 2 +- .../com/sdwfqin/quicklib/base/Constants.java | 3 ++ .../quicklib/module/wechat/pay/WechatPay.java | 2 +- 7 files changed, 84 insertions(+), 6 deletions(-) create mode 100644 app/src/main/java/com/sdwfqin/quickseed/wxapi/WXPayEntryActivity.java create mode 100644 app/src/main/res/layout/pay_result.xml diff --git a/ReadMe.md b/ReadMe.md index 5072798..520180d 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -11,15 +11,13 @@ implementation 'com.github.bumptech.glide:glide:4.6.1' annotationProcessor 'com.github.bumptech.glide:compiler:4.6.1' - implementation 'com.sdwfqin.quicklib:quicklib:1.1.7' + implementation 'com.sdwfqin.quicklib:quicklib:1.1.8' > 最低支持api16,编译版本27,gradle4.1 minSdkVersion 16 targetSdkVersion 27 -# 微信支付无法获取结果回调,正在修复 - # 注意事项 1. 当前项目依赖Qmui 1.0.7,即在主项目中配置了Qmui,quicklib中的样式无需再次配置就与主项目中的样式一致,后期可能会脱离出来 @@ -40,7 +38,7 @@ |- MvpFragment |- RxPresenter Presenter层封装 |- AliPayTools 支付宝支付工具类 - |- WechatPay 微信支付工具类 + |- WechatPayTools 微信支付工具类 |- WechatShareTools 微信分享工具类 |- QrBarScanActivity 解析二维码Activity |- QrCreateCode 创建二维码工具类 @@ -71,3 +69,25 @@ # Apk http://fir.im/x97v +# 微信支付 + +1. 调用WechatPayTools下面的wechatPayApp方法 +2. 如果想要支付回掉结果请参照示例app下面的WXPayEntryActivity +3. 注意下面的部分 + + ``` + + + // 注意WXPayEntryActivity下面的这个方法 + @Override + public void onResp(BaseResp resp) { + //回掉结果监听 + WechatPay.getInstance().onResp(resp.errCode); + LogUtils.e("onPayFinish, errCode = " + resp.errCode); + finish(); + } + ``` + diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 6f073f0..619b4c8 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -48,6 +48,10 @@ + \ No newline at end of file diff --git a/app/src/main/java/com/sdwfqin/quickseed/wxapi/WXPayEntryActivity.java b/app/src/main/java/com/sdwfqin/quickseed/wxapi/WXPayEntryActivity.java new file mode 100644 index 0000000..0976f73 --- /dev/null +++ b/app/src/main/java/com/sdwfqin/quickseed/wxapi/WXPayEntryActivity.java @@ -0,0 +1,47 @@ +package com.sdwfqin.quickseed.wxapi; + +import android.app.Activity; +import android.content.Intent; +import android.os.Bundle; + +import com.blankj.utilcode.util.LogUtils; +import com.sdwfqin.quicklib.base.Constants; +import com.sdwfqin.quicklib.module.wechat.pay.WechatPay; +import com.sdwfqin.quickseed.R; +import com.tencent.mm.opensdk.modelbase.BaseReq; +import com.tencent.mm.opensdk.modelbase.BaseResp; +import com.tencent.mm.opensdk.openapi.IWXAPI; +import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler; +import com.tencent.mm.opensdk.openapi.WXAPIFactory; + +public class WXPayEntryActivity extends Activity implements IWXAPIEventHandler { + + private IWXAPI api; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.pay_result); + + api = WXAPIFactory.createWXAPI(this, Constants.APP_ID); + api.handleIntent(getIntent(), this); + } + + @Override + protected void onNewIntent(Intent intent) { + super.onNewIntent(intent); + setIntent(intent); + api.handleIntent(intent, this); + } + + @Override + public void onReq(BaseReq req) { + } + + @Override + public void onResp(BaseResp resp) { + WechatPay.getInstance().onResp(resp.errCode); + LogUtils.e("onPayFinish, errCode = " + resp.errCode); + finish(); + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/pay_result.xml b/app/src/main/res/layout/pay_result.xml new file mode 100644 index 0000000..00031cf --- /dev/null +++ b/app/src/main/res/layout/pay_result.xml @@ -0,0 +1,4 @@ + + \ No newline at end of file diff --git a/quicklib/build.gradle b/quicklib/build.gradle index 745d6c1..2cb443f 100644 --- a/quicklib/build.gradle +++ b/quicklib/build.gradle @@ -2,7 +2,7 @@ apply plugin: 'com.android.library' apply plugin: 'com.github.dcendents.android-maven' apply plugin: 'com.jfrog.bintray' -version = "1.1.7_beta1" +version = "1.1.8" // gradlew install // gradlew bintrayUpload diff --git a/quicklib/src/main/java/com/sdwfqin/quicklib/base/Constants.java b/quicklib/src/main/java/com/sdwfqin/quicklib/base/Constants.java index d8a4ce8..16fa6ec 100644 --- a/quicklib/src/main/java/com/sdwfqin/quicklib/base/Constants.java +++ b/quicklib/src/main/java/com/sdwfqin/quicklib/base/Constants.java @@ -29,6 +29,9 @@ public class Constants { public static boolean LOG_TYPE = true; + public static String APP_ID = "123456789"; + + public static final String HEAD = "\n" + "\n" + " \n" + diff --git a/quicklib/src/main/java/com/sdwfqin/quicklib/module/wechat/pay/WechatPay.java b/quicklib/src/main/java/com/sdwfqin/quicklib/module/wechat/pay/WechatPay.java index 5ab705e..70e2b7b 100644 --- a/quicklib/src/main/java/com/sdwfqin/quicklib/module/wechat/pay/WechatPay.java +++ b/quicklib/src/main/java/com/sdwfqin/quicklib/module/wechat/pay/WechatPay.java @@ -42,7 +42,7 @@ public static WechatPay getInstance() { return sMWechatPay; } - public IWXAPI getWXApi() { + public IWXAPI getWXApi() { return mWXApi; }