From cc5af5b07fc24c4bf9e84727519efeb08864ed24 Mon Sep 17 00:00:00 2001 From: devzwy Date: Wed, 18 May 2022 17:05:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=83=A8=E5=88=86=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E4=B8=BA=E7=A9=BA=E6=97=B6=E6=97=A0=E6=B3=95=E8=B0=83?= =?UTF-8?q?=E8=B5=B7=E5=BE=AE=E4=BF=A1=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=9B?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=E9=9D=9E=E7=A9=BA=E5=BF=85=E5=A1=AB=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E4=BC=A0=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/github/socialhelper/demo/MainActivity.kt | 7 ++++++- .../demo/wxapi/WxPayEntryActivity.kt | 4 ++-- SocialHelper/src/main/AndroidManifest.xml | 2 ++ WeChat/proguard-rules.pro | 13 ++++++++++++- .../wechat/WeChatSocialEntryActivity.kt | 13 +------------ .../wechat/WeChatSocialHelperExt.kt | 17 ++++++++++------- .../wechat/WeChatSocialPayEntryActivity.kt | 9 ++------- WeChat/src/main/res/values/strings.xml | 4 +++- 8 files changed, 38 insertions(+), 31 deletions(-) diff --git a/Sample/src/main/java/io/github/socialhelper/demo/MainActivity.kt b/Sample/src/main/java/io/github/socialhelper/demo/MainActivity.kt index 3eb89b4..e4165c9 100644 --- a/Sample/src/main/java/io/github/socialhelper/demo/MainActivity.kt +++ b/Sample/src/main/java/io/github/socialhelper/demo/MainActivity.kt @@ -25,7 +25,12 @@ class MainActivity : AppCompatActivity() { // Toast.makeText(this,it,Toast.LENGTH_LONG).show() // }) - SocialHelper.startWeChatPay("1365026102","wx271754067562114fedb5565b1827663000","D94996F23D4542B277F35756122DEF7C") +// SocialHelper.startWeChatPay("1365026102","wx271754067562114fedb5565b1827663000","C380BEC2BFD727A4B6845133519F3AD6",{ +// Toast.makeText(this,"支付成功",Toast.LENGTH_LONG).show() +// },{ +// Toast.makeText(this,it,Toast.LENGTH_LONG).show() +// }) + // SocialHelper.getUserInfo("56_qoH8DaSoiTeRKWA-KHd6ExkKKK3j9N5v5ykfvJ22D3OG97hUFOzY_Xr-VHWS4SVErlh3Ox3Mp6p8sAieRQfhmgzN-OBslqxG6PKFhyvWZAQ","oHyiq6WWtG8-xgJDWWYMvShFRNyU",{ // Toast.makeText(this,it.toJsonStr(), Toast.LENGTH_LONG).show() diff --git a/Sample/src/main/java/io/github/socialhelper/demo/wxapi/WxPayEntryActivity.kt b/Sample/src/main/java/io/github/socialhelper/demo/wxapi/WxPayEntryActivity.kt index 25396f8..38e3576 100644 --- a/Sample/src/main/java/io/github/socialhelper/demo/wxapi/WxPayEntryActivity.kt +++ b/Sample/src/main/java/io/github/socialhelper/demo/wxapi/WxPayEntryActivity.kt @@ -1,6 +1,6 @@ package io.github.socialhelper.demo.wxapi -import io.github.socialhelper.wechat.WeChatSocialPayEntryActivity +import io.github.socialhelper.wechat.WeChatSocialEntryActivity -class WxPayEntryActivity:WeChatSocialPayEntryActivity() { +class WxPayEntryActivity: WeChatSocialEntryActivity() { } \ No newline at end of file diff --git a/SocialHelper/src/main/AndroidManifest.xml b/SocialHelper/src/main/AndroidManifest.xml index e030285..4cb1bcb 100644 --- a/SocialHelper/src/main/AndroidManifest.xml +++ b/SocialHelper/src/main/AndroidManifest.xml @@ -2,4 +2,6 @@ + + \ No newline at end of file diff --git a/WeChat/proguard-rules.pro b/WeChat/proguard-rules.pro index 481bb43..1ecc6e2 100644 --- a/WeChat/proguard-rules.pro +++ b/WeChat/proguard-rules.pro @@ -18,4 +18,15 @@ # If you keep the line number information, uncomment this to # hide the original source file name. -#-renamesourcefileattribute SourceFile \ No newline at end of file +#-renamesourcefileattribute SourceFile +-keep class com.tencent.mm.opensdk.** { + *; +} + +-keep class com.tencent.wxop.** { + *; +} + +-keep class com.tencent.mm.sdk.** { + *; +} \ No newline at end of file diff --git a/WeChat/src/main/java/io/github/socialhelper/wechat/WeChatSocialEntryActivity.kt b/WeChat/src/main/java/io/github/socialhelper/wechat/WeChatSocialEntryActivity.kt index 71d77d7..0f44ff5 100644 --- a/WeChat/src/main/java/io/github/socialhelper/wechat/WeChatSocialEntryActivity.kt +++ b/WeChat/src/main/java/io/github/socialhelper/wechat/WeChatSocialEntryActivity.kt @@ -55,18 +55,7 @@ open class WeChatSocialEntryActivity : Activity(), IWXAPIEventHandler { when (mBaseResp.type) { WECHAT_RESULT_TYPE_LOGIN -> { //授权回调 - (mBaseResp as SendAuth.Resp).also { sendAuthResp -> - sendAuthResp.authResult.yes { - onReqAuthSucc(sendAuthResp) - }.otherwise { - mWeChatReqAuthErrorListener( - if (sendAuthResp.errStr == null) application.getString( - R.string.social_wechat_resp_auth_fail - ) else sendAuthResp.errStr - ) - } - } - + onReqAuthSucc(mBaseResp as SendAuth.Resp) } WECHAT_RESULT_TYPE_SHARE -> { diff --git a/WeChat/src/main/java/io/github/socialhelper/wechat/WeChatSocialHelperExt.kt b/WeChat/src/main/java/io/github/socialhelper/wechat/WeChatSocialHelperExt.kt index fa51246..ae51f43 100644 --- a/WeChat/src/main/java/io/github/socialhelper/wechat/WeChatSocialHelperExt.kt +++ b/WeChat/src/main/java/io/github/socialhelper/wechat/WeChatSocialHelperExt.kt @@ -33,6 +33,11 @@ var mWeChatReqShareSuccessListener: (() -> Unit)? = null //微信分享结果错误回传接口 var mWeChatReqShareErrorListener: ((String) -> Unit)? = null +//微信支付结果回传接口 +lateinit var mWeChatReqPaySuccessListener: () -> Unit + +//微信支付结果错误回传接口 +lateinit var mWeChatReqPayErrorListener: (String) -> Unit /** * 发起微信授权 如果配置了appSecretKey则会返回 authCode + accessToken,否则将只返回 authCode @@ -97,7 +102,7 @@ fun SocialHelper.getUserInfo( fun SocialHelper.shareTextToWeChat( weChatShareType: WeChatShareType, text: String, - description: String? = null, + description: String, onShareSuccess: (() -> Unit)? = null, onShareError: ((String) -> Unit)? = null ) { @@ -113,9 +118,7 @@ fun SocialHelper.shareTextToWeChat( mWXMediaMessage.mediaObject = WXTextObject().also { it.text = text } - (description.isNullOrEmpty()).no { mWXMediaMessage.description = description - } } scene = getShareScene(weChatShareType) }) @@ -175,7 +178,7 @@ fun SocialHelper.shareImageToWeChat( fun SocialHelper.shareMusicToWeChat( weChatShareType: WeChatShareType, musicUrl: String, - musicTitle: String?=null, + musicTitle: String, musicDescription: String?=null, thumbBitmap: Bitmap? = null, onShareSuccess: (() -> Unit)? = null, @@ -286,7 +289,7 @@ fun SocialHelper.shareWebPageToWeChat( weChatShareType: WeChatShareType, webpageUrl: String, webpageTitle: String?=null, - webpageDescription: String?=null, + webpageDescription: String, thumbBitmap: Bitmap? = null, onShareSuccess: (() -> Unit)? = null, onShareError: ((String) -> Unit)? = null @@ -398,9 +401,9 @@ fun SocialHelper.shareMiniProgramToWeChat( * 发起微信支付 * [partnerId] 商户号 请填写商户号mchid对应的值。示例值:1900000109 * [prepayid] 预支付交易会话ID 微信返回的支付交易会话ID,该值有效期为2小时。 示例值: WX1217752501201407033233368018 - * + * [sign] 签名 */ -fun SocialHelper.startWeChatPay(partnerId:String,prepayId:String,sign:String){ +fun SocialHelper.startWeChatPay(partnerId:String,prepayId:String,sign:String,onPaySuccess:()->Unit,onPayError:(String)->Unit){ regWeChatSDK(this) diff --git a/WeChat/src/main/java/io/github/socialhelper/wechat/WeChatSocialPayEntryActivity.kt b/WeChat/src/main/java/io/github/socialhelper/wechat/WeChatSocialPayEntryActivity.kt index de0faab..24704c0 100644 --- a/WeChat/src/main/java/io/github/socialhelper/wechat/WeChatSocialPayEntryActivity.kt +++ b/WeChat/src/main/java/io/github/socialhelper/wechat/WeChatSocialPayEntryActivity.kt @@ -45,17 +45,12 @@ open class WeChatSocialPayEntryActivity : Activity(), IWXAPIEventHandler { (mBaseResp.errCode == BaseResp.ErrCode.ERR_OK).yes { "${localClassName}->onResp():mBaseResp:${mBaseResp.toJsonStr()}".logD() - - + mWeChatReqPaySuccessListener() }.otherwise { - + mWeChatReqPayErrorListener( if (mBaseResp.errCode == BaseResp.ErrCode.ERR_USER_CANCEL) application.getString(R.string.social_wechat_pay_cancel_err) else (if (mBaseResp.errStr.isNullOrEmpty()) getString(R.string.social_wechat_pay_other_err,mBaseResp.errCode) else mBaseResp.errStr)) "${localClassName}->onResp():mBaseResp:${mBaseResp.toJsonStr()}".logE() - } - mWeChatReqShareErrorListener = null - mWeChatReqShareSuccessListener = null - finish() } diff --git a/WeChat/src/main/res/values/strings.xml b/WeChat/src/main/res/values/strings.xml index 68dd526..52d7172 100644 --- a/WeChat/src/main/res/values/strings.xml +++ b/WeChat/src/main/res/values/strings.xml @@ -1,10 +1,12 @@ 微信未安装,请安装微信后再试 授权被取消 - 授权验证失败 accessToken获取失败,%s 用户资料获取失败,%d 分享失败,%d + 用户取消支付 + 支付失败,%d + \ No newline at end of file