提交 c0e1c434 authored 作者: 孙普伦's avatar 孙普伦 提交者: jarvanmo

bump to 3.9.0

上级 876c74c5
# 3.9.0
* 支持微信卡包
# 3.8.5
* Fix #471
......
......@@ -2,8 +2,10 @@ package com.jarvan.fluwx
import android.content.Context
import android.content.Intent
import android.util.Log
import androidx.annotation.NonNull
import com.jarvan.fluwx.handlers.*
import com.jarvan.fluwx.utils.WXApiUtils
import com.tencent.mm.opensdk.modelbiz.*
import com.tencent.mm.opensdk.modelpay.PayReq
import io.flutter.embedding.engine.plugins.FlutterPlugin
......@@ -80,10 +82,34 @@ class FluwxPlugin : FlutterPlugin, MethodCallHandler, ActivityAware,
result
)
call.method == "openBusinessView" -> openBusinessView(call, result)
call.method == "openWeChatInvoice" -> openWeChatInvoice(call, result);
else -> result.notImplemented()
}
}
private fun openWeChatInvoice(call: MethodCall, result: Result) {
if (WXAPiHandler.wxApi == null) {
result.error("Unassigned WxApi", "please config wxapi first", null)
return
} else {
//android 只有ChooseCard, IOS直接有ChooseInvoice
val request = ChooseCardFromWXCardPackage.Req()
request.cardType = call.argument("cardType")
request.appId = call.argument("appId")
request.locationId = call.argument("locationId")
request.cardId = call.argument("cardId")
request.canMultiSelect = call.argument("canMultiSelect")
request.timeStamp = System.currentTimeMillis().toString()
request.nonceStr = System.currentTimeMillis().toString()
request.signType = "SHA1"
request.cardSign = WXApiUtils.createSign(request.appId, request.nonceStr, request.timeStamp, request.cardType)
val done = WXAPiHandler.wxApi?.sendReq(request)
result.success(done)
}
}
override fun onDetachedFromEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) {
shareHandler?.onDestroy()
authHandler?.removeAllListeners()
......
......@@ -40,8 +40,20 @@ object FluwxResponseHandler {
is WXOpenBusinessWebview.Resp -> handlerWXOpenBusinessWebviewResponse(response)
is WXOpenCustomerServiceChat.Resp -> handlerWXOpenCustomerServiceChatResponse(response)
is WXOpenBusinessView.Resp -> handleWXOpenBusinessView(response)
is ChooseCardFromWXCardPackage.Resp -> handleWXOpenInvoiceResponse(response)
}
}
private fun handleWXOpenInvoiceResponse(response: ChooseCardFromWXCardPackage.Resp) {
val result = mapOf(
"cardItemList" to response.cardItemList,
"transaction" to response.transaction,
"openid" to response.openId,
errStr to response.errStr,
type to response.type,
errCode to response.errCode)
FluwxPlugin.callingChannel?.invokeMethod("onOpenWechatInvoiceResponse", result)
}
private fun handleWXOpenBusinessView(response: WXOpenBusinessView.Resp) {
val result = mapOf(
......
package com.jarvan.fluwx.utils;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;
public class WXApiUtils {
public static String createSign(String appId, String nonceStr, String timestamp, String card_type) {
SortedMap<Object, Object> parameters = new TreeMap<>();
parameters.put("app_id", appId);
parameters.put("nonce_str", nonceStr);
parameters.put("card_type", timestamp);
parameters.put("time_stamp", card_type);
StringBuffer sb = new StringBuffer();
Set es = parameters.entrySet();
// 所有参与传参的参数按照accsii排序(升序)
Iterator it = es.iterator();
while (it.hasNext()) {
@SuppressWarnings("rawtypes")
Map.Entry entry = (Map.Entry) it.next();
String k = (String) entry.getKey();
Object v = entry.getValue();
if (null != v && !"".equals(v) && !"sign".equals(k)
&& !"key".equals(k)) {
sb.append(k + "=" + v + "&");
}
}
String sign = shaEncode(sb.toString()).toUpperCase();
return sign;
}
public static String shaEncode(String inStr) {
MessageDigest sha = null;
try {
sha = MessageDigest.getInstance("SHA");
} catch (Exception e) {
System.out.println(e.toString());
e.printStackTrace();
return "";
}
byte[] byteArray = new byte[0];
try {
byteArray = inStr.getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
byte[] md5Bytes = sha.digest(byteArray);
StringBuffer hexValue = new StringBuffer();
for (int i = 0; i < md5Bytes.length; i++) {
int val = ((int) md5Bytes[i]) & 0xff;
if (val < 16) {
hexValue.append("0");
}
hexValue.append(Integer.toHexString(val));
}
return hexValue.toString();
}
}
......@@ -73,10 +73,6 @@ FlutterMethodChannel *channel = nil;
[_fluwxAuthHandler stopAuthByQRCode:call result:result];
} else if ([@"openWXApp" isEqualToString:call.method]) {
result(@([WXApi openWXApp]));
} else if ([@"payWithFluwx" isEqualToString:call.method]) {
[self handlePayment:call result:result];
} else if ([@"payWithHongKongWallet" isEqualToString:call.method]) {
[self handleHongKongWalletPayment:call result:result];
} else if ([@"launchMiniProgram" isEqualToString:call.method]) {
[self handleLaunchMiniProgram:call result:result];
} else if ([@"subscribeMsg" isEqualToString:call.method]) {
......@@ -97,11 +93,29 @@ FlutterMethodChannel *channel = nil;
[self openWeChatCustomerServiceChat:call result:result];
} else if ([@"checkSupportOpenBusinessView" isEqualToString:call.method]) {
[self checkSupportOpenBusinessView:call result:result];
}else {
} else if([@"openWeChatInvoice" isEqualToString:call.method]) {
[self openWeChatInvoice:call result:result];
} else {
result(FlutterMethodNotImplemented);
}
}
- (void)openWeChatInvoice:(FlutterMethodCall *)call result:(FlutterResult)result {
NSString *appId = call.arguments[@"appId"];
if ([FluwxStringUtil isBlank:appId]) {
result([FlutterError errorWithCode:@"invalid app id" message:@"are you sure your app id is correct ? " details:appId]);
return;
}
[WXApiRequestHandler chooseInvoice: appId
timestamp:[[NSDate date] timeIntervalSince1970]
completion:^(BOOL done) {
result(@(done));
}];
}
- (void)registerApp:(FlutterMethodCall *)call result:(FlutterResult)result {
NSNumber* doOnIOS =call.arguments[@"iOS"];
......@@ -198,7 +212,7 @@ FlutterMethodChannel *channel = nil;
- (void)handleHongKongWalletPayment:(FlutterMethodCall *)call result:(FlutterResult)result {
NSString *partnerId = call.arguments[@"prepayId"];
WXOpenBusinessWebViewReq *req = [[WXOpenBusinessWebViewReq alloc] init];
req.businessType = 1;
NSMutableDictionary *queryInfoDic = [NSMutableDictionary dictionary];
......
......@@ -92,11 +92,44 @@ FlutterMethodChannel *fluwxMethodChannel = nil;
[_delegate managerDidRecvChooseCardResponse:chooseCardResp];
}
} else if ([resp isKindOfClass:[WXChooseInvoiceResp class]]) {
if (_delegate
&& [_delegate respondsToSelector:@selector(managerDidRecvChooseInvoiceResponse:)]) {
WXChooseInvoiceResp *chooseInvoiceResp = (WXChooseInvoiceResp *) resp;
[_delegate managerDidRecvChooseInvoiceResponse:chooseInvoiceResp];
//TODO 处理发票返回,并回调Dart
WXChooseInvoiceResp *chooseInvoiceResp = (WXChooseInvoiceResp *) resp;
NSArray *array = chooseInvoiceResp.cardAry;
NSMutableArray *mutableArray = [NSMutableArray arrayWithCapacity:array.count];
for (int i = 0; i< array.count; i++) {
WXInvoiceItem *item = array[i];
NSDictionary *dict = @{@"app_id":item.appID, @"encrypt_code":item.encryptCode, @"card_id":item.cardId};
[mutableArray addObject:dict];
}
NSError *error = nil;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:mutableArray options:NSJSONWritingPrettyPrinted error: &error];
NSString *cardItemList = @"";
if ([jsonData length] && error == nil) {
cardItemList = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
}
NSDictionary *result = @{
description: chooseInvoiceResp.description == nil ? @"" : chooseInvoiceResp.description,
errStr: chooseInvoiceResp.errStr == nil ? @"" : chooseInvoiceResp.errStr,
errCode: @(chooseInvoiceResp.errCode),
type: @(chooseInvoiceResp.type),
@"cardItemList":cardItemList
};
[fluwxMethodChannel invokeMethod:@"onOpenWechatInvoiceResponse" arguments:result];
} else if ([resp isKindOfClass:[WXSubscribeMsgResp class]]) {
if ([_delegate respondsToSelector:@selector(managerDidRecvSubscribeMsgResponse:)]) {
[_delegate managerDidRecvSubscribeMsgResponse:(WXSubscribeMsgResp *) resp];
......
......@@ -125,16 +125,15 @@ NS_ASSUME_NONNULL_BEGIN
timestamp:(UInt32)timestamp
completion:(void (^ __nullable)(BOOL success))completion;
+ (void)openUrl:(NSString *)url
completion:(void (^ __nullable)(BOOL success))completion;
+ (void)chooseInvoice:(NSString *)appid
cardSign:(NSString *)cardSign
nonceStr:(NSString *)nonceStr
signType:(NSString *)signType
timestamp:(UInt32)timestamp
completion:(void (^ __nullable)(BOOL success))completion;
+ (void)openUrl:(NSString *)url
completion:(void (^ __nullable)(BOOL success))completion;
+ (void)sendPayment:(NSString *)appId
PartnerId:(NSString *)partnerId
......
......@@ -326,6 +326,19 @@
}
+ (void)chooseInvoice:(NSString *)appid
timestamp:(UInt32)timestamp
completion:(void (^ __nullable)(BOOL success))completion {
WXChooseInvoiceReq *chooseInvoiceReq = [[WXChooseInvoiceReq alloc] init];
chooseInvoiceReq.appID = appid;
chooseInvoiceReq.timeStamp = timestamp;
chooseInvoiceReq.signType = @"SHA1";
chooseInvoiceReq.cardSign = @"";
chooseInvoiceReq.nonceStr = @"";
[WXApi sendReq:chooseInvoiceReq completion:completion];
}
+ (void)sendAuthRequestScope:(NSString *)scope
State:(NSString *)state
OpenID:(NSString *)openID
......
......@@ -314,7 +314,7 @@ Future<bool> checkSupportOpenBusinessView() async {
return await _channel.invokeMethod("checkSupportOpenBusinessView");
}
///open wechat invoice list
Future<bool> openWeChatInvoice({
required String appId,
required String cardType,
......
......@@ -46,6 +46,8 @@ Map<String, _WeChatResponseInvoker> _nameAndResponseMapper = {
WeChatOpenCustomerServiceChatResponse.fromMap(argument),
"onOpenBusinessViewResponse": (Map argument) =>
WeChatOpenBusinessViewResponse.fromMap(argument),
"onOpenWechatInvoiceResponse": (Map argument) =>
WeChatOpenInvoiceResponse.fromMap(argument),
};
class BaseWeChatResponse {
......@@ -66,6 +68,13 @@ class BaseWeChatResponse {
bool get isSuccessful => errCode == 0;
}
class WeChatOpenInvoiceResponse extends BaseWeChatResponse {
String? cardItemList;
WeChatOpenInvoiceResponse.fromMap(Map map)
: cardItemList = map["cardItemList"],
super._(map[_errCode], map[_errStr]);
}
class WeChatShareResponse extends BaseWeChatResponse {
WeChatShareResponse.fromMap(Map map)
: type = map['type'],
......
name: fluwx
description: The capability of implementing WeChat SDKs in Flutter. With Fluwx, developers can use WeChatSDK easily, such as sharing, payment, lanuch mini program and etc.
version: 3.8.5
version: 3.9.0
homepage: https://github.com/JarvanMo/fluwx
environment:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论