M3(批3): 微信分享 + 登录(@tencent/wechat_open_sdk)
依赖:ohpm i @tencent/wechat_open_sdk@1.0.19(feature_capabilities)
T-M3-13 ShareProvider:friendsSharetypeUrlToptitleDescript → SendMessageToWXReq(scene 会话/朋友圈)
+ WXWebpageObject → 回传 sharesuccess{success(2成功/3取消),type(1好友/2朋友圈)}。
type 2截图/3图片/4视频暂回退网页分享(TODO);微信未安装回 cancel 不卡死
T-M3-14 LoginProvider:accreditlogin("1"=QQ空实现/其他=微信) → SendAuthReq(scope snsapi_userinfo) → 取 code。
🔴 AppSecret 不入端:code 换 profile 必须服务端,无端点时记录 code+TODO,不推不完整 sharelogin(红线)
WeChatApi 单例:createWXAPI(AppID wxd2bd650e06bdfe58 公开标识) + sendReq + handleWant 路由 onResp
EntryAbility.onCreate/onNewWant → WeChatApi.handleWant(接收微信回调)
module.json5:querySchemes ["weixin"](isWXAppInstalled)
运行期成功前提(已注释说明):微信开放平台注册本 HarmonyOS 应用(bundleName+指纹绑 AppID)、登录 profile 需服务端 code 换取端点。
devecocli build 通过(CompileArkTS 编译微信代码无误)。
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
"lockfileVersion": 3,
|
||||
"ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.",
|
||||
"specifiers": {
|
||||
"@tencent/wechat_open_sdk@^1.0.19": "@tencent/wechat_open_sdk@1.0.19",
|
||||
"common@../common": "common@../common",
|
||||
"contracts@../contracts": "contracts@../contracts",
|
||||
"domain_resource@../domain_resource": "domain_resource@../domain_resource",
|
||||
@@ -14,6 +15,13 @@
|
||||
"platform@../platform": "platform@../platform"
|
||||
},
|
||||
"packages": {
|
||||
"@tencent/wechat_open_sdk@1.0.19": {
|
||||
"name": "@tencent/wechat_open_sdk",
|
||||
"version": "1.0.19",
|
||||
"integrity": "sha512-elkkyMZVolWyhULd6zA+7xdHPRAhVja5ugyHvw/UpmeWrGfthHzNS6QtMZDMntzo7dFTNOxi8GAVvZmRA1uPBQ==",
|
||||
"resolved": "https://ohpm.openharmony.cn/ohpm/@tencent/wechat_open_sdk/-/wechat_open_sdk-1.0.19.har",
|
||||
"registryType": "ohpm"
|
||||
},
|
||||
"common@../common": {
|
||||
"name": "common",
|
||||
"version": "1.0.0",
|
||||
@@ -60,7 +68,8 @@
|
||||
"common": "file:../common",
|
||||
"platform": "file:../platform",
|
||||
"domain_resource": "file:../domain_resource",
|
||||
"feature_bridge": "file:../feature_bridge"
|
||||
"feature_bridge": "file:../feature_bridge",
|
||||
"@tencent/wechat_open_sdk": "^1.0.19"
|
||||
}
|
||||
},
|
||||
"platform@../platform": {
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
*/
|
||||
import { CapabilityProvider, EchoSampleProvider, RoomStubProvider, PayStubProvider,
|
||||
VibrateProvider, ClipboardProvider, AppSystemProvider, DeviceProvider,
|
||||
NetworkProvider } from 'feature_capabilities';
|
||||
NetworkProvider, ShareProvider, LoginProvider } from 'feature_capabilities';
|
||||
|
||||
export function buildCapabilities(): CapabilityProvider[] {
|
||||
return [
|
||||
@@ -18,6 +18,8 @@ export function buildCapabilities(): CapabilityProvider[] {
|
||||
new ClipboardProvider(), // gameCopytext/gamepastetext
|
||||
new DeviceProvider(), // getTime/getphonestate/getbattery/getwifiLevel/getphoneInfo/getmarketname/getothername/getOther/getcompareCode
|
||||
new NetworkProvider(), // getnetwork + 出站广播
|
||||
new ShareProvider(), // friendsSharetypeUrlToptitleDescript → sharesuccess(微信)
|
||||
new LoginProvider(), // accreditlogin → sharelogin(微信 code 模式,profile 待服务端)
|
||||
// —— 暂缓能力占位桩(§6.5)——
|
||||
new RoomStubProvider(),
|
||||
new PayStubProvider(),
|
||||
|
||||
@@ -2,6 +2,7 @@ import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.Ab
|
||||
import { hilog } from '@kit.PerformanceAnalysisKit';
|
||||
import { window } from '@kit.ArkUI';
|
||||
import { EventBus } from 'common';
|
||||
import { WeChatApi } from 'feature_capabilities';
|
||||
import { AppEvents } from '../routes/AppRoutes';
|
||||
|
||||
const DOMAIN = 0x0000;
|
||||
@@ -14,6 +15,14 @@ export default class EntryAbility extends UIAbility {
|
||||
hilog.error(DOMAIN, 'testTag', 'Failed to set colorMode. Cause: %{public}s', JSON.stringify(err));
|
||||
}
|
||||
hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate');
|
||||
// 微信回调(冷启动经 want 拉回):交 SDK 解析 → 路由到 Share/Login 回调
|
||||
WeChatApi.getInstance().handleWant(want);
|
||||
}
|
||||
|
||||
onNewWant(want: Want, _launchParam: AbilityConstant.LaunchParam): void {
|
||||
// 微信回调(应用已在后台时拉回)
|
||||
hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onNewWant');
|
||||
WeChatApi.getInstance().handleWant(want);
|
||||
}
|
||||
|
||||
onDestroy(): void {
|
||||
|
||||
@@ -10,6 +10,9 @@
|
||||
"deliveryWithInstall": true,
|
||||
"installationFree": false,
|
||||
"pages": "$profile:main_pages",
|
||||
"querySchemes": [
|
||||
"weixin"
|
||||
],
|
||||
"abilities": [
|
||||
{
|
||||
"name": "EntryAbility",
|
||||
|
||||
Reference in New Issue
Block a user