提交 b37b1b67 authored 作者: nelson1110's avatar nelson1110

Android wx pay done

上级 ae537025
/*___Generated_by_IDEA___*/
package com.jarvan.fluwx;
/* This stub is only used by the IDE. It is NOT the BuildConfig class actually packed into the APK */
public final class BuildConfig {
public final static boolean DEBUG = Boolean.parseBoolean(null);
}
\ No newline at end of file
/*___Generated_by_IDEA___*/
package com.jarvan.fluwx;
/* This stub is only used by the IDE. It is NOT the Manifest class actually packed into the APK */
public final class Manifest {
}
\ No newline at end of file
/*___Generated_by_IDEA___*/
package com.jarvan.fluwx;
/* This stub is only used by the IDE. It is NOT the R class actually packed into the APK */
public final class R {
}
\ No newline at end of file
......@@ -2,10 +2,7 @@ package com.jarvan.fluwx
import com.jarvan.fluwx.constant.WeChatPluginMethods
import com.jarvan.fluwx.constant.WeChatPluginMethods.IS_WE_CHAT_INSTALLED
import com.jarvan.fluwx.handler.FluwxAuthHandler
import com.jarvan.fluwx.handler.FluwxResponseHandler
import com.jarvan.fluwx.handler.FluwxShareHandler
import com.jarvan.fluwx.handler.WXAPiHandler
import com.jarvan.fluwx.handler.*
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
import io.flutter.plugin.common.MethodChannel.MethodCallHandler
......@@ -48,11 +45,18 @@ class FluwxPlugin(private var registrar: Registrar) : MethodCallHandler {
return
}
if(call.method == WeChatPluginMethods.PAY){
FluwxPayHandler.pay(call,result)
return
}
if (call.method.startsWith("share")) {
FluwxShareHandler.handle(call, result)
} else {
result.notImplemented()
}
}
}
......@@ -19,4 +19,7 @@ public class WeChatPluginMethods {
public static final String SHARE_WEB_PAGE = "shareWebPage";
public static final String SHARE_MINI_PROGRAM = "shareMiniProgram";
public static final String PAY = "pay";
public static final String WE_CHAT_PAY_RESPONSE = "onPayResponse";
}
package com.jarvan.fluwx.handler
import com.jarvan.fluwx.constant.CallResult
import com.jarvan.fluwx.constant.WechatPluginKeys
import com.tencent.mm.opensdk.modelpay.PayReq
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
object FluwxPayHandler {
fun pay(call: MethodCall, result: MethodChannel.Result) {
if (WXAPiHandler.wxApi == null) {
result.error(CallResult.RESULT_API_NULL, "please config wxapi first", null)
return
}else{
val request = PayReq()
request.appId = call.argument("appId")
request.partnerId = call.argument("partnerId")
request.prepayId= call.argument("prepayId")
request.packageValue = call.argument("packageValue")
request.nonceStr= call.argument("nonceStr")
request.timeStamp= call.argument("timeStamp")
request.sign= call.argument("sign")
request.signType= call.argument("signType")
request.extData=call.argument("extData")
val done = WXAPiHandler.wxApi!!.sendReq(request)
result.success(
mapOf(
WechatPluginKeys.PLATFORM to WechatPluginKeys.ANDROID,
WechatPluginKeys.RESULT to done
)
)
}
}
}
\ No newline at end of file
......@@ -5,6 +5,7 @@ import com.jarvan.fluwx.constant.WechatPluginKeys
import com.tencent.mm.opensdk.modelbase.BaseResp
import com.tencent.mm.opensdk.modelmsg.SendAuth
import com.tencent.mm.opensdk.modelmsg.SendMessageToWX
import com.tencent.mm.opensdk.modelpay.PayResp
import io.flutter.plugin.common.MethodChannel
object FluwxResponseHandler {
......@@ -27,9 +28,27 @@ object FluwxResponseHandler {
handleAuthResponse(response)
}else if (response is SendMessageToWX.Resp){
handleSendMessageResp(response)
}else if(response is PayResp){
handlePayResp(response)
}
}
private fun handlePayResp(response: PayResp) {
val result = mapOf(
"prepayId" to response.prepayId,
"returnKey" to response.returnKey,
"extData" to response.extData,
errStr to response.errStr,
WechatPluginKeys.TRANSACTION to response.transaction,
type to response.type,
errCode to response.errCode,
openId to response.openId,
WechatPluginKeys.PLATFORM to WechatPluginKeys.ANDROID
)
channel?.invokeMethod(WeChatPluginMethods.WE_CHAT_PAY_RESPONSE, result)
}
private fun handleSendMessageResp(response: SendMessageToWX.Resp) {
val result = mapOf(
errStr to response.errStr,
......@@ -60,4 +79,6 @@ object FluwxResponseHandler {
)
channel?.invokeMethod("onAuthResponse", result)
}
}
\ No newline at end of file
/*___Generated_by_IDEA___*/
package com.jarvan.fluwxexample;
/* This stub is only used by the IDE. It is NOT the BuildConfig class actually packed into the APK */
public final class BuildConfig {
public final static boolean DEBUG = Boolean.parseBoolean(null);
}
\ No newline at end of file
/*___Generated_by_IDEA___*/
package com.jarvan.fluwxexample;
/* This stub is only used by the IDE. It is NOT the Manifest class actually packed into the APK */
public final class Manifest {
}
\ No newline at end of file
/*___Generated_by_IDEA___*/
package com.jarvan.fluwxexample;
/* This stub is only used by the IDE. It is NOT the R class actually packed into the APK */
public final class R {
}
\ No newline at end of file
......@@ -5,3 +5,4 @@ export 'src/models/flutter_register_model.dart';
export 'src/models/wechat_share_models.dart';
export 'src/wechat_reponse.dart';
export 'src/wechat_scene.dart';
export 'src/models/wechat_pay_model.dart';
......@@ -5,6 +5,7 @@ import 'package:flutter/services.dart';
import 'models/flutter_register_model.dart';
import 'models/wechat_share_models.dart';
import 'models/wechat_send_auth_model.dart';
import 'models/wechat_pay_model.dart';
class Fluwx {
static const Map<Type, String> _shareModelMethodMapper = {
WeChatShareTextModel: "shareText",
......@@ -23,8 +24,12 @@ class Fluwx {
StreamController<Map> _responseFromAuthController =
new StreamController.broadcast();
StreamController<Map> _responseFromPayController =
new StreamController.broadcast();
Stream<Map> get responseFromShare => _responseFromShareController.stream;
Stream<Map> get responseFromAuth => _responseFromAuthController.stream;
Stream<Map> get responseFromPay => _responseFromPayController.stream;
///the [model] should not be null
static Future registerApp(RegisterModel model) async {
return await _channel.invokeMethod("registerApp", model.toMap());
......@@ -41,6 +46,7 @@ class Fluwx {
void disposeAll() {
_responseFromShareController.close();
_responseFromAuthController.close();
_responseFromPayController.close();
}
void disposeResponseFromShare(){
......@@ -51,6 +57,10 @@ class Fluwx {
_responseFromAuthController.close();
}
void disposeResponseFromPay(){
_responseFromPayController.close();
}
///the [model] can not be null
///see [WeChatShareWebPageModel]
/// [WeChatShareTextModel]
......@@ -79,8 +89,14 @@ class Fluwx {
_responseFromShareController.add(methodCall.arguments);
}else if("onAuthResponse" == methodCall.method){
_responseFromAuthController.add(methodCall.arguments);
}else if("onPayResponse" == methodCall.method){
_responseFromPayController.add(methodCall.arguments);
}
return Future.value(true);
}
Future pay(WeChatPayModel model) async {
return await _channel.invokeMethod("pay",model.toMap());
}
}
class WeChatPayModel{
final appId;
final partnerId;
final prepayId;
final packageValue;
final nonceStr;
final timeStamp;
final sign;
final signType;
final extData;
WeChatPayModel(this.appId, this.partnerId, this.prepayId, this.packageValue,
this.nonceStr, this.timeStamp, this.sign,{this.signType, this.extData});
Map toMap() {
return {
"appId":appId,
"partnerId":partnerId,
"prepayId":prepayId,
"packageValue":packageValue,
"nonceStr":nonceStr,
"timeStamp":timeStamp,
"sign":sign,
"signType":signType,
"extData":extData,
};
}
}
\ No newline at end of file
import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart';
import '../wechat_scene.dart';
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论