Skip to content
This repository has been archived by the owner on Mar 28, 2024. It is now read-only.

Commit

Permalink
修复部分字段为空时无法调起微信的问题;改为非空必填参数传入
Browse files Browse the repository at this point in the history
  • Loading branch information
devzwy committed May 18, 2022
1 parent bfd437e commit cc5af5b
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
@@ -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() {
}
2 changes: 2 additions & 0 deletions SocialHelper/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="io.github.social">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
</manifest>
13 changes: 12 additions & 1 deletion WeChat/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,15 @@

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
#-renamesourcefileattribute SourceFile
-keep class com.tencent.mm.opensdk.** {
*;
}

-keep class com.tencent.wxop.** {
*;
}

-keep class com.tencent.mm.sdk.** {
*;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
) {
Expand All @@ -113,9 +118,7 @@ fun SocialHelper.shareTextToWeChat(
mWXMediaMessage.mediaObject = WXTextObject().also {
it.text = text
}
(description.isNullOrEmpty()).no {
mWXMediaMessage.description = description
}
}
scene = getShareScene(weChatShareType)
})
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()

}
Expand Down
4 changes: 3 additions & 1 deletion WeChat/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<resources>
<string name="social_not_install_wechat_app_tip">微信未安装,请安装微信后再试</string>
<string name="social_wechat_req_auth_cancel">授权被取消</string>
<string name="social_wechat_resp_auth_fail">授权验证失败</string>
<string name="social_wechat_get_access_token_err">accessToken获取失败,%s</string>
<string name="social_wechat_get_user_info_err">用户资料获取失败,%d</string>
<string name="social_wechat_share_err">分享失败,%d</string>
<string name="social_wechat_pay_cancel_err">用户取消支付</string>
<string name="social_wechat_pay_other_err">支付失败,%d</string>



</resources>

0 comments on commit cc5af5b

Please sign in to comment.