Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/fluwx_no_pay/ohos

This file was deleted.

9 changes: 9 additions & 0 deletions packages/fluwx_no_pay/ohos/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
.cxx
10 changes: 10 additions & 0 deletions packages/fluwx_no_pay/ohos/build-profile.json5
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"apiType": "stageMode",
"buildOption": {
},
"targets": [
{
"name": "default"
}
]
}
2 changes: 2 additions & 0 deletions packages/fluwx_no_pay/ohos/hvigorfile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently.
export { harTasks } from '@ohos/hvigor-ohos-plugin';
17 changes: 17 additions & 0 deletions packages/fluwx_no_pay/ohos/index.ets
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import FluwxPlugin from './src/main/ets/components/plugin/FluwxPlugin';
export default FluwxPlugin;
12 changes: 12 additions & 0 deletions packages/fluwx_no_pay/ohos/oh-package.json5
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "fluwx_no_pay",
"version": "1.0.0",
"description": "Please describe the basic information.",
"main": "index.ets",
"author": "",
"license": "Apache-2.0",
"dependencies": {
"@ohos/flutter_ohos": "file:./har/flutter.har",
"@tencent/wechat_open_sdk": "1.0.19"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,300 @@
import {
AbilityAware,
AbilityPluginBinding,
FlutterPlugin,
FlutterPluginBinding,
MethodCall,
MethodCallHandler,
MethodChannel,
MethodResult,
NewWantListener,
} from '@ohos/flutter_ohos';
import * as wechatSDK from "@tencent/wechat_open_sdk"
import { FluwxAuthHandler } from './handlers/FluwxAuthHandler';
import { AbilityConstant, common, Want } from '@kit.AbilityKit';
import { WXAPiHandler } from './handlers/WXAPiHandler';
import { FluwxShareHandler } from './handlers/FluwxShareHandler';

const MESSAGE_CHANNEL_NAME = "com.jarvanmo/fluwx"
const KEY_ERR_STR = "errStr"
const KEY_ERR_CODE = "errCode"
const KEY_OPEN_ID = "openId"
const KEY_TYPE = "type"

/** FluwxPlugin **/
export default class FluwxPlugin implements FlutterPlugin, MethodCallHandler, AbilityAware, NewWantListener, wechatSDK.WXApiEventHandler {
private channel: MethodChannel | null = null;
private appContext: common.Context | null = null;
private uiContext: common.UIAbilityContext | null = null;
private binding: AbilityPluginBinding | null = null
private authHandler: FluwxAuthHandler | null = null;
private shareHandler: FluwxShareHandler | null = null;
private extMsg: string | null = null;

getUniqueClassName(): string {
return "FluwxPlugin"
}

onAttachedToEngine(binding: FlutterPluginBinding): void {
this.channel = new MethodChannel(binding.getBinaryMessenger(), MESSAGE_CHANNEL_NAME);
this.channel.setMethodCallHandler(this)
this.appContext = binding.getApplicationContext();
this.authHandler = new FluwxAuthHandler(this.channel);
this.shareHandler = new FluwxShareHandler();
}

onDetachedFromEngine(binding: FlutterPluginBinding): void {
this.channel = null;
this.appContext = null;
this.authHandler = null;
this.shareHandler = null;
}

onAttachedToAbility(binding: AbilityPluginBinding): void {
this.binding = binding
this.uiContext = binding.getAbility().context;
WXAPiHandler.setContext(this.uiContext);
binding.addOnNewWantListener(this)
}

onDetachedFromAbility(): void {
this.binding?.removeOnNewWantListener(this)
this.binding = null
this.uiContext = null;
}

onMethodCall(call: MethodCall, result: MethodResult): void {
if (call.method.startsWith("share")) {
this.shareHandler?.share(call, result);
return;
}

switch (call.method) {
case "isWeChatInstalled":
WXAPiHandler.checkWeChatInstallation(result);
break;
case "registerApp":
WXAPiHandler.registerApp(call, result, this);
break;
case "sendAuth":
this.authHandler?.sendAuth(call, result);
break;
case "authByQRCode":
this.authHandler?.authByQRCode(call, result);
break;
case "stopAuthByQRCode":
this.authHandler?.stopAuthByQRCode(result);
break;
case "payWithFluwx":
this.handlePay(call, result);
break;
case "payWithHongKongWallet":
// TODO
result.notImplemented();
break;
case "launchMiniProgram":
this.launchMiniProgram(call, result);
break;
case "subscribeMsg":
// TODO
result.notImplemented();
break;
case "autoDeduct":
// TODO
result.notImplemented();
break;
case "autoDeductV2":
// TODO
result.notImplemented();
break;
case "openWXApp":
result.success(WXAPiHandler.wxApi?.openWechat(this.uiContext));
break;
case "getExtMsg":
result.success(this.extMsg);
this.extMsg = null;
break;
case "openWeChatCustomerServiceChat":
this.openWeChatCustomerServiceChat(call, result);
break;
case "checkSupportOpenBusinessView":
WXAPiHandler.checkSupportOpenBusinessView(result);
break;
case "openBusinessView":
this.openBusinessView(call, result);
break;
case "openWeChatInvoice":
// TODO
result.notImplemented();
break;
case "openUrl":
// TODO
result.notImplemented();
break;
case "openRankList":
// TODO
result.notImplemented();
break;
case "attemptToResumeMsgFromWx":
this.attemptToResumeMsgFromWx(result);
break;
case "selfCheck":
result.success(null)
break;
default:
result.notImplemented();
}
}

onNewWant(want: Want, launchParams: AbilityConstant.LaunchParam): void {
WXAPiHandler.wxApi?.handleWant(want, this);
}

// 微信回调 start

onReq = (req: wechatSDK.BaseReq): void => {
if (req instanceof wechatSDK.LaunchFromWXReq) {
const _result: Map<string, ESObject> = new Map();
_result.set("extMsg", req.message?.messageExt);
_result.set("messageAction", req.message?.messageAction);
_result.set("lang", req.lang);
_result.set("country", req.country);
this.channel?.invokeMethod("onWXLaunchFromWX", _result);
}
}

onResp = (resp: wechatSDK.BaseResp): void => {
if (resp instanceof wechatSDK.SendAuthResp) {
this.onAuthResponse(resp);
return;
}

if (resp instanceof wechatSDK.SendMessageToWXResp) {
this.onSendMessageToWXResp(resp);
return;
}

if (resp instanceof wechatSDK.PayResp) {
this.onPayResp(resp);
return;
}

if (resp instanceof wechatSDK.LaunchMiniProgramResp) {
this.onLaunchMiniProgramResp(resp);
return;
}
}

// 微信回调 end

onAuthResponse(resp: wechatSDK.SendAuthResp) {
const result: Map<string, ESObject> = new Map();
result.set(KEY_ERR_CODE, resp.errCode);
result.set(KEY_ERR_STR, resp.errStr);
result.set("code", resp.code);
result.set("state", resp.state);
result.set("lang", resp.lang);
result.set("country", resp.country);
result.set(KEY_OPEN_ID, resp.openId);
result.set("url", resp.url);
result.set(KEY_TYPE, resp.type);

this.channel?.invokeMethod("onAuthResponse", result);
}

onSendMessageToWXResp(resp: wechatSDK.SendMessageToWXResp) {
const _result: Map<string, ESObject> = new Map();
_result.set(KEY_ERR_CODE, resp.errCode);
_result.set(KEY_ERR_STR, resp.errStr);
_result.set(KEY_TYPE, resp.type);
_result.set(KEY_OPEN_ID, resp.openId);

this.channel?.invokeMethod("onShareResponse", _result);
}

onPayResp(resp: wechatSDK.PayResp) {
const _result: Map<string, ESObject> = new Map();
_result.set(KEY_ERR_CODE, resp.errCode);
_result.set(KEY_ERR_STR, resp.errStr);
_result.set(KEY_TYPE, resp.type);
_result.set("prepayId", resp.prepayId);
_result.set("returnKey", resp.returnKey);
_result.set("extData", resp.extData);

this.channel?.invokeMethod("onPayResponse", _result);
}

onLaunchMiniProgramResp(resp: wechatSDK.LaunchMiniProgramResp) {
const _result: Map<string, ESObject> = new Map();
_result.set(KEY_ERR_CODE, resp.errCode);
_result.set(KEY_ERR_STR, resp.errStr);
_result.set(KEY_TYPE, resp.type);
_result.set(KEY_OPEN_ID, resp.openId);

if (resp.extMsg) {
_result.set("extMsg", resp.extMsg);
}

this.channel?.invokeMethod("onLaunchMiniProgramResponse", _result);
}

async handlePay(call: MethodCall, result: MethodResult) {
if (!WXAPiHandler.wxApi) {
result.error("Unassigned WxApi", "please config wxapi first", null);
return;
}

const request = new wechatSDK.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").toString();
request.sign = call.argument("sign");
request.signType = call.argument("signType");
request.extData = call.argument("extData");

const done = await WXAPiHandler.wxApi?.sendReq(this.uiContext, request);

result.success(done);
}

attemptToResumeMsgFromWx(result: MethodResult) {
WXAPiHandler.wxApi?.handleWant(this.binding?.getAbility().launchWant, this)
result.success(null)
}

async launchMiniProgram(call: MethodCall, result: MethodResult) {
const request = new wechatSDK.LaunchMiniProgramReq();
request.userName = call.argument("userName");
request.path = call.argument("path");
// sdk 内当前没 type 常量, 直接使用传入的参数
request.miniprogramType = call.argument("miniProgramType") ?? 0;

const done = await WXAPiHandler.wxApi?.sendReq(this.uiContext, request);

result.success(done);
}

async openBusinessView(call: MethodCall, result: MethodResult) {
const request = new wechatSDK.OpenBusinessViewReq();
request.businessType = call.argument("businessType");
request.query = call.argument("query");
request.extInfo = `{"miniProgramType": 0}`;

const done = await WXAPiHandler.wxApi?.sendReq(this.uiContext, request);

result.success(done);
}

async openWeChatCustomerServiceChat(call: MethodCall, result: MethodResult) {
const request = new wechatSDK.OpenCustomerServiceChatReq();
request.corpId = call.argument("corpId") ?? "";
request.url = call.argument("url") ?? "";

const done = await WXAPiHandler.wxApi?.sendReq(this.uiContext, request);

result.success(done);
}
}
Loading