新增feature weiXinJsSdk 来支持jssdk api调用

This commit is contained in:
Wang Kejun 2023-04-18 17:59:46 +08:00
parent 3bf5d75dad
commit d406b70579
34 changed files with 1367 additions and 184 deletions

View File

@ -49,6 +49,15 @@ declare type GeneralAspectDict<ED extends EntityDict, Cxt extends BackendRuntime
type: AppType;
domain: string;
}, context: Cxt) => Promise<string>;
signatureJsSDK: (params: {
url: string;
env: WebEnv;
}, context: Cxt) => Promise<{
signature: any;
noncestr: string;
timestamp: number;
appId: string;
}>;
updateConfig: (params: {
entity: 'platform' | 'system';
entityId: string;

View File

@ -1,7 +1,17 @@
import { EntityDict } from "../general-app-domain";
import { AppType } from "../general-app-domain/Application/Schema";
import { BackendRuntimeContext } from "../context/BackendRuntimeContext";
import { WebEnv } from '../general-app-domain/Token/Schema';
export declare function getApplication<ED extends EntityDict, Cxt extends BackendRuntimeContext<ED>>(params: {
type: AppType;
domain: string;
}, context: Cxt): Promise<string>;
export declare function signatureJsSDK<ED extends EntityDict, Cxt extends BackendRuntimeContext<ED>>({ url, env }: {
url: string;
env: WebEnv;
}, context: Cxt): Promise<{
signature: any;
noncestr: string;
timestamp: number;
appId: string;
}>;

View File

@ -1,9 +1,10 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getApplication = void 0;
exports.signatureJsSDK = exports.getApplication = void 0;
var tslib_1 = require("tslib");
var assert_1 = require("oak-domain/lib/utils/assert");
var projection_1 = require("../types/projection");
var oak_external_sdk_1 = require("oak-external-sdk");
function getApplication(params, context) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var type, domain, url, _a, application, _b, application2;
@ -73,3 +74,25 @@ function getApplication(params, context) {
});
}
exports.getApplication = getApplication;
function signatureJsSDK(_a, context) {
var url = _a.url, env = _a.env;
return tslib_1.__awaiter(this, void 0, void 0, function () {
var application, _b, type, config, systemId, config2, appId, appSecret, wechatInstance, result;
return tslib_1.__generator(this, function (_c) {
switch (_c.label) {
case 0:
application = context.getApplication();
_b = application, type = _b.type, config = _b.config, systemId = _b.systemId;
(0, assert_1.assert)(type === 'wechatPublic' && config.type === 'wechatPublic');
config2 = config;
appId = config2.appId, appSecret = config2.appSecret;
wechatInstance = oak_external_sdk_1.WechatSDK.getInstance(appId, 'wechatPublic', appSecret);
return [4 /*yield*/, wechatInstance.signatureJsSDK({ url: url })];
case 1:
result = _c.sent();
return [2 /*return*/, result];
}
});
});
}
exports.signatureJsSDK = signatureJsSDK;

View File

@ -1,6 +1,6 @@
import { loginByMobile, loginWechat, loginWechatMp, syncUserInfoWechatMp, sendCaptcha, switchTo, refreshWechatPublicUserInfo, getWechatMpUserPhoneNumber, logout } from './token';
import { getUploadInfo } from './extraFile';
import { getApplication } from './application';
import { getApplication, signatureJsSDK } from './application';
import { updateConfig, updateApplicationConfig } from './config';
import { mergeUser } from './user';
declare const aspectDict: {
@ -18,5 +18,6 @@ declare const aspectDict: {
updateApplicationConfig: typeof updateApplicationConfig;
getWechatMpUserPhoneNumber: typeof getWechatMpUserPhoneNumber;
logout: typeof logout;
signatureJsSDK: typeof signatureJsSDK;
};
export default aspectDict;

View File

@ -20,5 +20,6 @@ var aspectDict = {
updateApplicationConfig: config_1.updateApplicationConfig,
getWechatMpUserPhoneNumber: token_1.getWechatMpUserPhoneNumber,
logout: token_1.logout,
signatureJsSDK: application_1.signatureJsSDK,
};
exports.default = aspectDict;

View File

@ -10,7 +10,7 @@ exports.default = OakComponent({
name: '',
entityId: '',
type: '',
isService: false,
isService: true,
},
data: {
initialConfig: {},

View File

@ -21,8 +21,8 @@ function AppView(props) {
return null;
}
function render(props) {
var _a = props.data, entity = _a.entity, name = _a.name, type = _a.type, currentConfig = _a.currentConfig, dirty = _a.dirty, _b = _a.isService, isService = _b === void 0 ? true : _b;
var _c = props.methods, resetConfig = _c.resetConfig, updateConfig = _c.updateConfig, setValue = _c.setValue, removeItem = _c.removeItem, cleanKey = _c.cleanKey;
var _a = props.data, entity = _a.entity, name = _a.name, type = _a.type, currentConfig = _a.currentConfig, dirty = _a.dirty, isService = _a.isService;
var _b = props.methods, resetConfig = _b.resetConfig, updateConfig = _b.updateConfig, setValue = _b.setValue, removeItem = _b.removeItem, cleanKey = _b.cleanKey;
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(antd_1.Affix, tslib_1.__assign({ offsetTop: 64 }, { children: (0, jsx_runtime_1.jsx)(antd_1.Alert, { message: (0, jsx_runtime_1.jsx)("div", { children: (0, jsx_runtime_1.jsxs)("text", { children: ["\u60A8\u6B63\u5728\u66F4\u65B0", (0, jsx_runtime_1.jsx)(antd_1.Typography.Text, tslib_1.__assign({ keyboard: true, className: web_module_less_1.default.weight }, { children: entity })), "\u5BF9\u8C61", (0, jsx_runtime_1.jsx)(antd_1.Typography.Text, tslib_1.__assign({ keyboard: true, className: web_module_less_1.default.weight }, { children: name })), "\u7684\u914D\u7F6E\uFF0C\u8BF7\u8C28\u614E\u64CD\u4F5C"] }) }), type: "info", showIcon: true, action: (0, jsx_runtime_1.jsxs)(antd_1.Space, { children: [(0, jsx_runtime_1.jsx)(antd_1.Button, tslib_1.__assign({ disabled: !dirty, type: "primary", danger: true, onClick: function () { return resetConfig(); }, style: {
marginRight: 10,
} }, { children: "\u91CD\u7F6E" })), (0, jsx_runtime_1.jsx)(antd_1.Button, tslib_1.__assign({ disabled: !dirty, type: "primary", onClick: function () { return updateConfig(); } }, { children: "\u786E\u5B9A" }))] }) }) })), (0, jsx_runtime_1.jsx)("div", tslib_1.__assign({ className: web_module_less_1.default.container }, { children: (0, jsx_runtime_1.jsx)(antd_1.Tabs, { tabPosition: "left", items: [

View File

@ -11,6 +11,8 @@ function WechatMp(props) {
return setValue("appId", e.target.value);
} }) }) })), (0, jsx_runtime_1.jsx)(antd_1.Form.Item, tslib_1.__assign({ label: "appSecret", name: "appSecret" }, { children: (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsx)(antd_1.Input, { placeholder: "\u8BF7\u8F93\u5165appSecret", type: "text", value: config === null || config === void 0 ? void 0 : config.appSecret, onChange: function (e) {
return setValue("appSecret", e.target.value);
} }) }) })), (0, jsx_runtime_1.jsx)(antd_1.Form.Item, tslib_1.__assign({ label: "\u539F\u59CBID", name: "originalId" }, { children: (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsx)(antd_1.Input, { placeholder: "\u8BF7\u8F93\u5165\u539F\u59CBID", type: "text", value: config === null || config === void 0 ? void 0 : config.originalId, onChange: function (e) {
return setValue("originalId", e.target.value);
} }) }) })), (0, jsx_runtime_1.jsx)(antd_1.Form.Item, tslib_1.__assign({ label: "qrCodePrefix", name: "qrCodePrefix" }, { children: (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsx)(antd_1.Input, { placeholder: "\u8BF7\u8F93\u5165qrCodePrefix", type: "text", value: config === null || config === void 0 ? void 0 : config.qrCodePrefix, onChange: function (e) {
return setValue("qrCodePrefix", e.target.value);
} }) }) }))] }))] })), (0, jsx_runtime_1.jsxs)(antd_1.Col, tslib_1.__assign({ flex: "auto" }, { children: [(0, jsx_runtime_1.jsx)(antd_1.Divider, tslib_1.__assign({ orientation: "left", className: web_module_less_1.default.title }, { children: "\u5FAE\u4FE1\u5C0F\u7A0B\u5E8F-\u670D\u52A1\u5668\u914D\u7F6E" })), (0, jsx_runtime_1.jsxs)(antd_1.Form, tslib_1.__assign({ colon: true, labelAlign: "left", layout: "vertical", style: { marginTop: 10 } }, { children: [(0, jsx_runtime_1.jsx)(antd_1.Form.Item, tslib_1.__assign({ label: "\u670D\u52A1\u5668\u5730\u5740(URL)", name: "url" }, { children: (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsx)(antd_1.Input, { placeholder: "\u8BF7\u8F93\u5165\u670D\u52A1\u5668\u5730\u5740(URL)\uFF0C\u9009\u586B", type: "text", value: (_a = config === null || config === void 0 ? void 0 : config.server) === null || _a === void 0 ? void 0 : _a.url, onChange: function (e) {

View File

@ -15,6 +15,8 @@ function WechatPublic(props) {
return setValue("appId", e.target.value);
} }) }) })), (0, jsx_runtime_1.jsx)(antd_1.Form.Item, tslib_1.__assign({ label: "appSecret", name: "appSecret" }, { children: (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsx)(antd_1.Input, { placeholder: "\u8BF7\u8F93\u5165appSecret", type: "text", value: config === null || config === void 0 ? void 0 : config.appSecret, onChange: function (e) {
return setValue("appSecret", e.target.value);
} }) }) })), (0, jsx_runtime_1.jsx)(antd_1.Form.Item, tslib_1.__assign({ label: "\u539F\u59CBID", name: "originalId" }, { children: (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsx)(antd_1.Input, { placeholder: "\u8BF7\u8F93\u5165\u539F\u59CBID", type: "text", value: config === null || config === void 0 ? void 0 : config.originalId, onChange: function (e) {
return setValue("originalId", e.target.value);
} }) }) })), isService && ((0, jsx_runtime_1.jsx)(antd_1.Form.Item, tslib_1.__assign({ label: "\u662F\u5426\u4E3A\u670D\u52A1\u53F7", name: "isService" }, { children: (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsx)(antd_1.Switch, { checkedChildren: "\u662F", unCheckedChildren: "\u5426", checked: config === null || config === void 0 ? void 0 : config.isService, onChange: function (checked) {
return setValue("isService", checked);
} }) }) })))] }))] })), isService && ((0, jsx_runtime_1.jsxs)(antd_1.Col, tslib_1.__assign({ flex: "auto" }, { children: [(0, jsx_runtime_1.jsx)(antd_1.Divider, tslib_1.__assign({ orientation: "left", className: web_module_less_1.default.title }, { children: "\u5FAE\u4FE1\u516C\u4F17\u53F7-\u670D\u52A1\u5668\u914D\u7F6E" })), (0, jsx_runtime_1.jsxs)(antd_1.Form, tslib_1.__assign({ colon: true, labelAlign: "left", layout: "vertical", style: { marginTop: 10 } }, { children: [(0, jsx_runtime_1.jsx)(antd_1.Form.Item, tslib_1.__assign({ label: "\u670D\u52A1\u5668\u5730\u5740(URL)", name: "url" }, { children: (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsx)(antd_1.Input, { placeholder: "\u8BF7\u8F93\u5165\u670D\u52A1\u5668\u5730\u5740(URL)\uFF0C\u9009\u586B", type: "text", value: (_a = config === null || config === void 0 ? void 0 : config.server) === null || _a === void 0 ? void 0 : _a.url, onChange: function (e) {
@ -38,48 +40,6 @@ function WechatPublic(props) {
value: 'safe',
label: '安全模式',
},
] }) }) }))] }))] }))), isService && ((0, jsx_runtime_1.jsxs)(antd_1.Col, tslib_1.__assign({ flex: "auto" }, { children: [(0, jsx_runtime_1.jsx)(antd_1.Divider, tslib_1.__assign({ orientation: "left", className: web_module_less_1.default.title }, { children: "\u5FAE\u4FE1\u516C\u4F17\u53F7-\u6A21\u7248" })), (0, jsx_runtime_1.jsx)(antd_1.Tabs, { tabPosition: 'top', size: 'middle', type: "editable-card",
// hideAdd={!(Object.keys(templateMsgs).length > 0)}
onEdit: function (targetKey, action) {
if (action === 'add') {
setModal(true);
}
else {
cleanKey("templateMsgs", targetKey);
}
}, items: Object.keys(templateMsgs).length > 0
? Object.keys(templateMsgs).map(function (name, idx) {
var templateId = templateMsgs[name];
return {
key: "".concat(name),
label: "".concat(name),
children: ((0, jsx_runtime_1.jsx)(antd_1.Form, tslib_1.__assign({ colon: true, labelAlign: "left", layout: "vertical", style: { marginTop: 10 } }, { children: (0, jsx_runtime_1.jsx)(antd_1.Form.Item, tslib_1.__assign({ label: "templateId", name: "templateId" }, { children: (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsx)(antd_1.Input, { placeholder: "\u8BF7\u8F93\u5165templateId", type: "text", value: templateId, onChange: function (e) {
return setValue("templateMsgs.".concat(name), e.target
.value);
} }) }) })) }))),
};
})
: [] }), (0, jsx_runtime_1.jsx)(antd_1.Modal, tslib_1.__assign({ title: "\u65B0\u5EFA\u6A21\u7248\u6807\u7B7E", onCancel: function () {
setModal(false);
setMessageType('');
}, onOk: function () {
if (!messageType) {
antd_1.message.error({
content: '请输入标签名称',
});
return;
}
if (Object.keys(templateMsgs).includes(messageType)) {
antd_1.message.error({
content: '已存在相同的标签名,请重新输入',
});
return;
}
setValue("templateMsgs.".concat(messageType), '');
setModal(false);
setMessageType('');
}, open: open, cancelText: "\u53D6\u6D88", okText: "\u786E\u5B9A", destroyOnClose: true }, { children: (0, jsx_runtime_1.jsx)(antd_1.Form, tslib_1.__assign({ colon: true, labelAlign: "left", layout: "vertical", style: { marginTop: 10 } }, { children: (0, jsx_runtime_1.jsx)(antd_1.Form.Item, tslib_1.__assign({ label: "\u6807\u7B7E\u540D\u79F0", name: "messageType", help: "\u53EA\u80FD\u8F93\u5165\u82F1\u6587\u548C\u4E2D\u6587" }, { children: (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsx)(antd_1.Input, { placeholder: "\u8BF7\u8F93\u5165\u6807\u7B7E\u540D\u79F0", type: "text", value: messageType, onChange: function (e) {
return setMessageType(e.target.value.replace(/[0-9-.]/g, ''));
} }) }) })) })) }))] })))] })));
] }) }) }))] }))] })))] })));
}
exports.default = WechatPublic;

View File

@ -8,6 +8,7 @@ export declare type WechatMpConfig = {
type: 'wechatMp';
appId: string;
appSecret: string;
originalId: string;
qrCodePrefix?: string;
server?: {
url?: string;
@ -33,6 +34,7 @@ export declare type WechatPublicConfig = {
isService: boolean;
appId: string;
appSecret: string;
originalId: string;
templateMsgs?: WechatPublicTemplateMsgsConfig;
server?: {
url?: string;

View File

@ -3,6 +3,7 @@ import { Token } from './token';
import { ExtraFile } from './extraFile';
import { Application } from './application';
import { Config } from './config';
import { WeiXinJsSdk } from './weiXinJsSdk';
import { BasicFeatures } from 'oak-frontend-base/lib/features';
import { AspectDict } from '../aspects/AspectDict';
import { AppType } from '../general-app-domain/Application/Schema';
@ -15,4 +16,5 @@ export declare type GeneralFeatures<ED extends EntityDict, Cxt extends BackendRu
extraFile: ExtraFile<ED, Cxt, FrontCxt, AD>;
application: Application<ED, Cxt, FrontCxt, AD>;
config: Config<ED, Cxt, FrontCxt, AD>;
weiXinJsSdk: WeiXinJsSdk<ED, Cxt, FrontCxt, AD>;
};

View File

@ -5,16 +5,19 @@ var token_1 = require("./token");
var extraFile_1 = require("./extraFile");
var application_1 = require("./application");
var config_1 = require("./config");
var weiXinJsSdk_1 = require("./weiXinJsSdk");
function initialize(basicFeatures, type, domain) {
var application = new application_1.Application(type, domain, basicFeatures.cache, basicFeatures.localStorage);
var token = new token_1.Token(basicFeatures.cache, basicFeatures.localStorage);
var extraFile = new extraFile_1.ExtraFile(basicFeatures.cache, application);
var config = new config_1.Config(basicFeatures.cache);
var weiXinJsSdk = new weiXinJsSdk_1.WeiXinJsSdk(basicFeatures.cache, basicFeatures.localStorage);
return {
token: token,
extraFile: extraFile,
application: application,
config: config,
weiXinJsSdk: weiXinJsSdk,
};
}
exports.initialize = initialize;

1
lib/features/weiXinJsSdk.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export * from './weiXinJsSdk.web';

View File

@ -0,0 +1,5 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
console.warn('不应该跑到这里');
tslib_1.__exportStar(require("./weiXinJsSdk.web"), exports);

16
lib/features/weiXinJsSdk.mp.d.ts vendored Normal file
View File

@ -0,0 +1,16 @@
import { Feature } from 'oak-frontend-base/lib/types/Feature';
import { CommonAspectDict } from 'oak-common-aspect';
import { EntityDict } from '../general-app-domain';
import { AspectDict } from '../aspects/AspectDict';
import { BackendRuntimeContext } from '../context/BackendRuntimeContext';
import { FrontendRuntimeContext } from '../context/FrontendRuntimeContext';
import { Cache } from 'oak-frontend-base/lib/features/cache';
import { LocalStorage } from 'oak-frontend-base/lib/features/localStorage';
export declare class WeiXinJsSdk<ED extends EntityDict, Cxt extends BackendRuntimeContext<ED>, FrontCxt extends FrontendRuntimeContext<ED, Cxt, AD>, AD extends AspectDict<ED, Cxt> & CommonAspectDict<ED, Cxt>> extends Feature {
private cache;
private storage;
constructor(cache: Cache<ED, Cxt, FrontCxt, AD>, storage: LocalStorage);
wxConfig(): void;
initWeiXinJsSDK(): Promise<void>;
loadWeiXinJsSDK(): Promise<void>;
}

View File

@ -0,0 +1,35 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.WeiXinJsSdk = void 0;
var tslib_1 = require("tslib");
var Feature_1 = require("oak-frontend-base/lib/types/Feature");
var WeiXinJsSdk = /** @class */ (function (_super) {
tslib_1.__extends(WeiXinJsSdk, _super);
function WeiXinJsSdk(cache, storage) {
var _this = _super.call(this) || this;
_this.cache = cache;
_this.storage = storage;
return _this;
}
WeiXinJsSdk.prototype.wxConfig = function () {
console.warn('小程序无需该操作');
};
WeiXinJsSdk.prototype.initWeiXinJsSDK = function () {
return tslib_1.__awaiter(this, void 0, void 0, function () {
return tslib_1.__generator(this, function (_a) {
console.warn('小程序无需该操作');
return [2 /*return*/];
});
});
};
WeiXinJsSdk.prototype.loadWeiXinJsSDK = function () {
return tslib_1.__awaiter(this, void 0, void 0, function () {
return tslib_1.__generator(this, function (_a) {
console.warn('小程序无需该操作');
return [2 /*return*/];
});
});
};
return WeiXinJsSdk;
}(Feature_1.Feature));
exports.WeiXinJsSdk = WeiXinJsSdk;

30
lib/features/weiXinJsSdk.web.d.ts vendored Normal file
View File

@ -0,0 +1,30 @@
import { Feature } from 'oak-frontend-base/lib/types/Feature';
import { CommonAspectDict } from 'oak-common-aspect';
import { EntityDict } from '../general-app-domain';
import { AspectDict } from '../aspects/AspectDict';
import { BackendRuntimeContext } from '../context/BackendRuntimeContext';
import { FrontendRuntimeContext } from '../context/FrontendRuntimeContext';
import { Cache } from 'oak-frontend-base/lib/features/cache';
import { LocalStorage } from 'oak-frontend-base/lib/features/localStorage';
declare type Options = WeixinJsSdk.CheckJsApiOptions | WeixinJsSdk.AddCardOptions | WeixinJsSdk.ChooseCardOptions | WeixinJsSdk.OnMenuShareTimelineOptions | WeixinJsSdk.OnMenuShareAppMessageOptions | WeixinJsSdk.OnMenuShareQQ | WeixinJsSdk.OnMenuShareWeibo | WeixinJsSdk.OnMenuShareQZone | WeixinJsSdk.ChooseImageOptions | WeixinJsSdk.PreviewImageOptions | WeixinJsSdk.UploadImageOptions | WeixinJsSdk.DownloadImageOptions | WeixinJsSdk.GetLocalImgDataOptions | WeixinJsSdk.LocalVoiceOptions | WeixinJsSdk.UploadVoiceOptions | WeixinJsSdk.DownloadVoiceOptions | WeixinJsSdk.OpenLocationOptions | WeixinJsSdk.GetLocationOptions | WeixinJsSdk.ScanQRCodeOptions | WeixinJsSdk.OpenProductSpecificViewOptions | WeixinJsSdk.ChooseCardOptions | WeixinJsSdk.OpenCardOptions | WeixinJsSdk.ChooseWXPayOptions;
export declare class WeiXinJsSdk<ED extends EntityDict, Cxt extends BackendRuntimeContext<ED>, FrontCxt extends FrontendRuntimeContext<ED, Cxt, AD>, AD extends AspectDict<ED, Cxt> & CommonAspectDict<ED, Cxt>> extends Feature {
private cache;
private storage;
constructor(cache: Cache<ED, Cxt, FrontCxt, AD>, storage: LocalStorage);
signatureJsSDK(url: string): Promise<{
signature: any;
noncestr: string;
timestamp: number;
appId: string;
}>;
wxConfig(config: WeixinJsSdk.ConfigOptions): Promise<unknown>;
initWeiXinJsSDK(options?: {
jsApiList?: WeixinJsSdk.JSApis[];
openTagList?: string[];
}): Promise<unknown>;
/**
* jssdk
*/
loadWeiXinJsSDK(name: WeixinJsSdk.JSApis, options?: Options, jsApiList?: WeixinJsSdk.JSApis[], openTagList?: string[]): Promise<any>;
}
export {};

View File

@ -0,0 +1,142 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.WeiXinJsSdk = void 0;
var tslib_1 = require("tslib");
var Feature_1 = require("oak-frontend-base/lib/types/Feature");
var env_1 = require("../utils/env");
var lodash_1 = require("oak-domain/lib/utils/lodash");
// const weixin = require('weixin-js-sdk');
var weixin_js_sdk_1 = tslib_1.__importDefault(require("weixin-js-sdk"));
var WeiXinJsSdk = /** @class */ (function (_super) {
tslib_1.__extends(WeiXinJsSdk, _super);
function WeiXinJsSdk(cache, storage) {
var _this = _super.call(this) || this;
_this.cache = cache;
_this.storage = storage;
return _this;
}
WeiXinJsSdk.prototype.signatureJsSDK = function (url) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var env, result;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, (0, env_1.getEnv)()];
case 1:
env = _a.sent();
return [4 /*yield*/, this.cache.exec('signatureJsSDK', {
url: url,
env: env,
})];
case 2:
result = (_a.sent()).result;
return [2 /*return*/, result];
}
});
});
};
WeiXinJsSdk.prototype.wxConfig = function (config) {
return new Promise(function (resolve, reject) {
weixin_js_sdk_1.default.config(config);
weixin_js_sdk_1.default.ready(function () {
console.log('调用wx.config通过');
resolve('');
});
weixin_js_sdk_1.default.error(function (err) {
var error = "\u8C03\u7528wx.config\u51FA\u9519: ".concat(JSON.stringify(err), "\uFF0C\u8BF7\u91CD\u65B0\u5C1D\u8BD5");
reject(error);
});
});
};
WeiXinJsSdk.prototype.initWeiXinJsSDK = function (options) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var _a, jsApiList, openTagList, url, splitUrl, result, jsApiList2, openTagList2;
return tslib_1.__generator(this, function (_b) {
switch (_b.label) {
case 0:
_a = options || {}, jsApiList = _a.jsApiList, openTagList = _a.openTagList;
url = window.location.href;
splitUrl = url.split('#')[0];
return [4 /*yield*/, this.signatureJsSDK(splitUrl)];
case 1:
result = _b.sent();
jsApiList2 = [
'updateAppMessageShareData',
'updateTimelineShareData',
'onMenuShareTimeline',
'onMenuShareAppMessage',
'onMenuShareQQ',
'onMenuShareWeibo',
'getLocation',
'chooseWXPay',
'scanQRCode',
'openLocation',
'chooseImage',
'previewImage',
'uploadImage',
'downloadImage',
];
if (jsApiList && jsApiList instanceof Array) {
jsApiList2 = (0, lodash_1.uniq)(jsApiList2.concat(jsApiList));
}
openTagList2 = ['wx-open-launch-weapp'];
if (openTagList && openTagList instanceof Array) {
openTagList2 = (0, lodash_1.uniq)(openTagList2.concat(openTagList));
}
return [2 /*return*/, this.wxConfig({
debug: process.env.NODE_ENV === 'development',
appId: result.appId,
timestamp: result.timestamp,
nonceStr: result.noncestr,
signature: result.signature,
jsApiList: jsApiList2,
beta: false,
openTagList: openTagList2,
})];
}
});
});
};
/**
* 微信jssdk 传入方法名
*/
WeiXinJsSdk.prototype.loadWeiXinJsSDK = function (name, options, jsApiList, openTagList) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
/**
* 将小程序的API封装成支持Promise的API
*/
function wxPromisify(fn) {
return function (obj) {
if (obj === void 0) { obj = {}; }
return new Promise(function (resolve, reject) {
obj.success = function (res) {
resolve(res);
};
obj.fail = function (res) {
reject(res);
};
// 微信jsSdk api有cancel回调
obj.cancel = function () {
reject({ errMsg: 'request:cancel' });
};
fn(obj);
});
};
}
var fn, result;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.initWeiXinJsSDK({ jsApiList: jsApiList, openTagList: openTagList })];
case 1:
_a.sent();
fn = wxPromisify(weixin_js_sdk_1.default[name]);
return [4 /*yield*/, fn(options)];
case 2:
result = _a.sent();
return [2 /*return*/, result];
}
});
});
};
return WeiXinJsSdk;
}(Feature_1.Feature));
exports.WeiXinJsSdk = WeiXinJsSdk;

View File

@ -18,6 +18,7 @@ export declare type WechatMpConfig = {
type: 'wechatMp';
appId: string;
appSecret: string;
originalId: string;
qrCodePrefix?: string;
server?: {
url?: string;
@ -43,6 +44,7 @@ export declare type WechatPublicConfig = {
isService: boolean;
appId: string;
appSecret: string;
originalId: string;
templateMsgs?: WechatPublicTemplateMsgsConfig;
server?: {
url?: string;

View File

@ -27,7 +27,8 @@
"sha1": "^1.1.1",
"tslib": "^2.4.0",
"uuid": "^8.3.2",
"x2js": "^3.4.4"
"x2js": "^3.4.4",
"weixin-js-sdk": "^1.6.0"
},
"peerDependencies": {
"@ant-design/icons": "^4.7.0",

View File

@ -83,6 +83,18 @@ type GeneralAspectDict<
},
context: Cxt
) => Promise<string>;
signatureJsSDK: (
params: {
url: string;
env: WebEnv;
},
context: Cxt
) => Promise<{
signature: any;
noncestr: string;
timestamp: number;
appId: string;
}>;
updateConfig: (
params: {
entity: 'platform' | 'system';

View File

@ -1,8 +1,15 @@
import { assert } from 'oak-domain/lib/utils/assert';
import { EntityDict } from "../general-app-domain";
import { AppType } from "../general-app-domain/Application/Schema";
import { AppType, WechatPublicConfig } from "../general-app-domain/Application/Schema";
import { BackendRuntimeContext } from "../context/BackendRuntimeContext";
import { applicationProjection } from '../types/projection';
import {
WebEnv,
} from '../general-app-domain/Token/Schema';
import {
WechatPublicInstance,
WechatSDK,
} from 'oak-external-sdk';
export async function getApplication<
ED extends EntityDict,
@ -90,4 +97,25 @@ export async function getApplication<
}
return application.id as string;
}
export async function signatureJsSDK<
ED extends EntityDict,
Cxt extends BackendRuntimeContext<ED>
>({ url, env }: { url: string; env: WebEnv }, context: Cxt) {
const application = context.getApplication();
const { type, config, systemId } = application!;
assert(type === 'wechatPublic' && config!.type === 'wechatPublic');
const config2 = config as WechatPublicConfig;
const { appId, appSecret } = config2;
const wechatInstance = WechatSDK.getInstance(
appId,
'wechatPublic',
appSecret
) as WechatPublicInstance;
const result = await wechatInstance.signatureJsSDK({ url });
return result;
}

View File

@ -10,7 +10,7 @@ import {
logout,
} from './token';
import { getUploadInfo } from './extraFile';
import { getApplication } from './application';
import { getApplication, signatureJsSDK } from './application';
import { updateConfig, updateApplicationConfig } from './config';
import { mergeUser } from './user';
@ -29,6 +29,7 @@ const aspectDict = {
updateApplicationConfig,
getWechatMpUserPhoneNumber,
logout,
signatureJsSDK,
};
export default aspectDict;

View File

@ -12,7 +12,7 @@ export default OakComponent({
name: '',
entityId: '',
type: '',
isService: false,
isService: true,
},
data: {
initialConfig: {} as Config,

View File

@ -88,7 +88,7 @@ export default function render(
type,
currentConfig,
dirty,
isService = true,
isService,
} = props.data;
const { resetConfig, updateConfig, setValue, removeItem, cleanKey } =
props.methods;

View File

@ -67,6 +67,18 @@ export default function WechatMp(props: {
/>
</>
</Form.Item>
<Form.Item label="原始ID" name="originalId">
<>
<Input
placeholder="请输入原始ID"
type="text"
value={config?.originalId}
onChange={(e) =>
setValue(`originalId`, e.target.value)
}
/>
</>
</Form.Item>
<Form.Item label="qrCodePrefix" name="qrCodePrefix">
<>
<Input

View File

@ -15,7 +15,6 @@ import {
Select,
} from 'antd';
import Styles from './web.module.less';
import { MinusCircleOutlined, PlusOutlined } from '@ant-design/icons';
import {
AppType,
WechatPublicConfig,
@ -77,6 +76,18 @@ export default function WechatPublic(props: {
/>
</>
</Form.Item>
<Form.Item label="原始ID" name="originalId">
<>
<Input
placeholder="请输入原始ID"
type="text"
value={config?.originalId}
onChange={(e) =>
setValue(`originalId`, e.target.value)
}
/>
</>
</Form.Item>
{isService && (
<Form.Item label="是否为服务号" name="isService">
<>
@ -175,124 +186,6 @@ export default function WechatPublic(props: {
</Form>
</Col>
)}
{isService && (
<Col flex="auto">
<Divider orientation="left" className={Styles.title}>
-
</Divider>
<Tabs
tabPosition={'top'}
size={'middle'}
type="editable-card"
// hideAdd={!(Object.keys(templateMsgs).length > 0)}
onEdit={(targetKey: any, action: 'add' | 'remove') => {
if (action === 'add') {
setModal(true);
} else {
cleanKey(`templateMsgs`, targetKey);
}
}}
items={
Object.keys(templateMsgs).length > 0
? Object.keys(templateMsgs).map((name, idx) => {
const templateId = templateMsgs[name];
return {
key: `${name}`,
label: `${name}`,
children: (
<Form
colon={true}
labelAlign="left"
layout="vertical"
style={{ marginTop: 10 }}
>
<Form.Item
label="templateId"
name="templateId"
>
<>
<Input
placeholder="请输入templateId"
type="text"
value={templateId}
onChange={(e) =>
setValue(
`templateMsgs.${name}`,
e.target
.value
)
}
/>
</>
</Form.Item>
</Form>
),
};
})
: []
}
></Tabs>
<Modal
title="新建模版标签"
onCancel={() => {
setModal(false);
setMessageType('');
}}
onOk={() => {
if (!messageType) {
message.error({
content: '请输入标签名称',
});
return;
}
if (
Object.keys(templateMsgs).includes(messageType)
) {
message.error({
content: '已存在相同的标签名,请重新输入',
});
return;
}
setValue(`templateMsgs.${messageType}`, '');
setModal(false);
setMessageType('');
}}
open={open}
cancelText="取消"
okText="确定"
destroyOnClose={true}
>
<Form
colon={true}
labelAlign="left"
layout="vertical"
style={{ marginTop: 10 }}
>
<Form.Item
label="标签名称"
name="messageType"
help="只能输入英文和中文"
>
<>
<Input
placeholder="请输入标签名称"
type="text"
value={messageType}
onChange={(e) =>
setMessageType(
e.target.value.replace(
/[0-9-.]/g,
''
)
)
}
/>
</>
</Form.Item>
</Form>
</Modal>
</Col>
)}
</Space>
);
}

View File

@ -10,13 +10,14 @@ export type WechatMpConfig = {
type: 'wechatMp';
appId: string;
appSecret: string;
originalId: string; //原始id
qrCodePrefix?: string; // 扫描二维码跳转的前缀(在小程序后台配置必须统一跳转到weCharQrCode/scan/index)
server?: {
url?: string; //服务器地址(URL)
token: string; //令牌(Token)
encodingAESKey: string; //消息加解密密钥(EncodingAESKey)
mode: 'clear' | 'compatible' | 'safe'; //消息加解密方式 明文模式 兼容模式 安全模式
dataFormat: 'json' | 'xml'
dataFormat: 'json' | 'xml';
};
};
@ -38,6 +39,7 @@ export type WechatPublicConfig = {
isService: boolean; // 是否服务号
appId: string;
appSecret: string;
originalId: string; //原始id
templateMsgs?: WechatPublicTemplateMsgsConfig;
server?: {
url?: string; //服务器地址(URL)

View File

@ -72,10 +72,13 @@ export class Application<
}
private async loadApplicationInfo(type: AppType, domain: string) {
const { result: applicationId } = await this.cache.exec('getApplication', {
type,
domain,
});
const { result: applicationId } = await this.cache.exec(
'getApplication',
{
type,
domain,
}
);
this.applicationId = applicationId;
this.getApplicationFromCache();
@ -87,7 +90,7 @@ export class Application<
}
async initialize(appId?: string | null) {
if (process.env.NODE_ENV === 'development' && appId) {
if (process.env.NODE_ENV === 'development' && appId) {
// development环境下允许注入一个线上的appId
this.applicationId = appId;
}

View File

@ -3,6 +3,7 @@ import { Token } from './token';
import { ExtraFile } from './extraFile';
import { Application } from './application';
import { Config } from './config';
import { WeiXinJsSdk } from './weiXinJsSdk';
import { BasicFeatures } from 'oak-frontend-base/lib/features';
import { AspectDict } from '../aspects/AspectDict';
import { AspectWrapper } from 'oak-domain/lib/types';
@ -33,11 +34,17 @@ export function initialize<
);
const extraFile = new ExtraFile<ED, Cxt, FrontCxt, AD>(basicFeatures.cache, application);
const config = new Config<ED, Cxt, FrontCxt, AD>(basicFeatures.cache);
const weiXinJsSdk = new WeiXinJsSdk<ED, Cxt, FrontCxt, AD>(
basicFeatures.cache,
basicFeatures.localStorage
);
return {
token,
extraFile,
application,
config,
weiXinJsSdk,
};
}
@ -46,9 +53,10 @@ export type GeneralFeatures<
Cxt extends BackendRuntimeContext<ED>,
FrontCxt extends FrontendRuntimeContext<ED, Cxt, AD>,
AD extends AspectDict<ED, Cxt> & CommonAspectDict<ED, Cxt>
> = {
token: Token<ED, Cxt, FrontCxt, AD>;
extraFile: ExtraFile<ED, Cxt, FrontCxt, AD>;
application: Application<ED, Cxt, FrontCxt, AD>;
config: Config<ED, Cxt, FrontCxt, AD>;
};
> = {
token: Token<ED, Cxt, FrontCxt, AD>;
extraFile: ExtraFile<ED, Cxt, FrontCxt, AD>;
application: Application<ED, Cxt, FrontCxt, AD>;
config: Config<ED, Cxt, FrontCxt, AD>;
weiXinJsSdk: WeiXinJsSdk<ED, Cxt, FrontCxt, AD>;
};

View File

@ -0,0 +1,37 @@
import { Feature } from 'oak-frontend-base/lib/types/Feature';
import { CommonAspectDict } from 'oak-common-aspect';
import { EntityDict } from '../general-app-domain';
import { AspectDict } from '../aspects/AspectDict';
import { BackendRuntimeContext } from '../context/BackendRuntimeContext';
import { FrontendRuntimeContext } from '../context/FrontendRuntimeContext';
import { Cache } from 'oak-frontend-base/lib/features/cache';
import { LocalStorage } from 'oak-frontend-base/lib/features/localStorage';
export class WeiXinJsSdk<
ED extends EntityDict,
Cxt extends BackendRuntimeContext<ED>,
FrontCxt extends FrontendRuntimeContext<ED, Cxt, AD>,
AD extends AspectDict<ED, Cxt> & CommonAspectDict<ED, Cxt>
> extends Feature {
private cache: Cache<ED, Cxt, FrontCxt, AD & CommonAspectDict<ED, Cxt>>;
private storage: LocalStorage;
constructor(cache: Cache<ED, Cxt, FrontCxt, AD>, storage: LocalStorage) {
super();
this.cache = cache;
this.storage = storage;
}
wxConfig() {
console.warn('小程序无需该操作');
}
async initWeiXinJsSDK() {
console.warn('小程序无需该操作');
}
async loadWeiXinJsSDK() {
console.warn('小程序无需该操作');
}
}

View File

@ -0,0 +1,3 @@
console.warn('不应该跑到这里');
export * from './weiXinJsSdk.web';

View File

@ -0,0 +1,169 @@
import { Feature } from 'oak-frontend-base/lib/types/Feature';
import { CommonAspectDict } from 'oak-common-aspect';
import { EntityDict } from '../general-app-domain';
import { AspectDict } from '../aspects/AspectDict';
import { BackendRuntimeContext } from '../context/BackendRuntimeContext';
import { FrontendRuntimeContext } from '../context/FrontendRuntimeContext';
import { Cache } from 'oak-frontend-base/lib/features/cache';
import { LocalStorage } from 'oak-frontend-base/lib/features/localStorage';
import { getEnv } from '../utils/env';
import { WebEnv } from '../general-app-domain/Token/Schema';
import { uniq } from 'oak-domain/lib/utils/lodash';
// const weixin = require('weixin-js-sdk');
import weixin from 'weixin-js-sdk';
type Options =
| WeixinJsSdk.CheckJsApiOptions
| WeixinJsSdk.AddCardOptions
| WeixinJsSdk.ChooseCardOptions
| WeixinJsSdk.OnMenuShareTimelineOptions
| WeixinJsSdk.OnMenuShareAppMessageOptions
| WeixinJsSdk.OnMenuShareQQ
| WeixinJsSdk.OnMenuShareWeibo
| WeixinJsSdk.OnMenuShareQZone
| WeixinJsSdk.ChooseImageOptions
| WeixinJsSdk.PreviewImageOptions
| WeixinJsSdk.UploadImageOptions
| WeixinJsSdk.DownloadImageOptions
| WeixinJsSdk.GetLocalImgDataOptions
| WeixinJsSdk.LocalVoiceOptions
| WeixinJsSdk.UploadVoiceOptions
| WeixinJsSdk.DownloadVoiceOptions
| WeixinJsSdk.OpenLocationOptions
| WeixinJsSdk.GetLocationOptions
| WeixinJsSdk.ScanQRCodeOptions
| WeixinJsSdk.OpenProductSpecificViewOptions
| WeixinJsSdk.ChooseCardOptions
| WeixinJsSdk.OpenCardOptions
| WeixinJsSdk.ChooseWXPayOptions;
export class WeiXinJsSdk<
ED extends EntityDict,
Cxt extends BackendRuntimeContext<ED>,
FrontCxt extends FrontendRuntimeContext<ED, Cxt, AD>,
AD extends AspectDict<ED, Cxt> & CommonAspectDict<ED, Cxt>
> extends Feature {
private cache: Cache<ED, Cxt, FrontCxt, AD & CommonAspectDict<ED, Cxt>>;
private storage: LocalStorage;
constructor(cache: Cache<ED, Cxt, FrontCxt, AD>, storage: LocalStorage) {
super();
this.cache = cache;
this.storage = storage;
}
async signatureJsSDK(url: string) {
const env = await getEnv();
const { result } = await this.cache.exec('signatureJsSDK', {
url,
env: env as WebEnv,
});
return result;
}
wxConfig(config: WeixinJsSdk.ConfigOptions) {
return new Promise((resolve, reject) => {
weixin.config(config);
weixin.ready(() => {
console.log('调用wx.config通过');
resolve('');
});
weixin.error((err: any) => {
const error = `调用wx.config出错: ${JSON.stringify(
err
)}`;
reject(error);
});
});
}
async initWeiXinJsSDK(options?: {
jsApiList?: WeixinJsSdk.JSApis[];
openTagList?: string[];
}) {
const { jsApiList, openTagList } = options || {};
const url = window.location.href;
const splitUrl = url.split('#')[0];
const result = await this.signatureJsSDK(splitUrl); // 接口回来的是noncestr 不是nonceStr
let jsApiList2: WeixinJsSdk.JSApis[] = [
'updateAppMessageShareData',
'updateTimelineShareData',
'onMenuShareTimeline',
'onMenuShareAppMessage',
'onMenuShareQQ',
'onMenuShareWeibo',
'getLocation',
'chooseWXPay',
'scanQRCode',
'openLocation',
'chooseImage',
'previewImage',
'uploadImage',
'downloadImage',
];
if (jsApiList && jsApiList instanceof Array) {
jsApiList2 = uniq(jsApiList2.concat(jsApiList));
}
let openTagList2 = ['wx-open-launch-weapp'];
if (openTagList && openTagList instanceof Array) {
openTagList2 = uniq(openTagList2.concat(openTagList));
}
return this.wxConfig({
debug: process.env.NODE_ENV === 'development',
appId: result.appId,
timestamp: result.timestamp,
nonceStr: result.noncestr,
signature: result.signature,
jsApiList: jsApiList2,
beta: false,
openTagList: openTagList2,
});
}
/**
* jssdk
*/
async loadWeiXinJsSDK(
name: WeixinJsSdk.JSApis,
options?: Options,
jsApiList?: WeixinJsSdk.JSApis[],
openTagList?: string[]
) {
/**
* API封装成支持Promise的API
*/
function wxPromisify(fn: (obj: any) => any) {
return function (obj: any = {}): any {
return new Promise((resolve, reject) => {
obj.success = function (res: any) {
resolve(res);
};
obj.fail = function (res: any) {
reject(res);
};
// 微信jsSdk api有cancel回调
obj.cancel = function () {
reject({ errMsg: 'request:cancel' });
};
fn(obj);
});
};
}
await this.initWeiXinJsSDK({ jsApiList, openTagList });
const fn = wxPromisify((weixin as any)[name as any] as any);
const result = await fn(options);
return result;
}
}

770
typings/weixin-js-sdk.d.ts vendored Normal file
View File

@ -0,0 +1,770 @@
declare namespace WeixinJsSdk {
/** **************************************************************************
* Type definations
****************************************************************************/
type JSApis =
| 'updateAppMessageShareData'
| 'updateTimelineShareData'
| 'onMenuShareTimeline'
| 'onMenuShareAppMessage'
| 'onMenuShareQQ'
| 'onMenuShareWeibo'
| 'onMenuShareQZone'
| 'startRecord'
| 'stopRecord'
| 'onVoiceRecordEnd'
| 'playVoice'
| 'pauseVoice'
| 'stopVoice'
| 'onVoicePlayEnd'
| 'uploadVoice'
| 'downloadVoice'
| 'chooseImage'
| 'previewImage'
| 'uploadImage'
| 'downloadImage'
| 'translateVoice'
| 'getNetworkType'
| 'openLocation'
| 'getLocation'
| 'hideOptionMenu'
| 'showOptionMenu'
| 'hideMenuItems'
| 'showMenuItems'
| 'hideAllNonBaseMenuItem'
| 'showAllNonBaseMenuItem'
| 'closeWindow'
| 'scanQRCode'
| 'chooseWXPay'
| 'openProductSpecificView'
| 'addCard'
| 'chooseCard'
| 'openCard'
| 'checkJsApi'
| 'onRecordEnd'
| 'openWXDeviceLib'
| 'closeWXDeviceLib'
| 'configWXDeviceWiFi'
| 'getWXDeviceInfos'
| 'sendDataToWXDevice'
| 'startScanWXDevice'
| 'stopScanWXDevice'
| 'connectWXDevice'
| 'disconnectWXDevice'
| 'getWXDeviceTicket'
| 'WeixinJSBridgeReady'
| 'onWXDeviceBindStateChange'
| 'onWXDeviceStateChange'
| 'onScanWXDeviceResult'
| 'onReceiveDataFromWXDevice'
| 'onWXDeviceBluetoothStateChange';
type Menus =
| 'menuItem:exposeArticle' // 举报
| 'menuItem:setFont' // 调整字体
| 'menuItem:dayMode' // 日间模式
| 'menuItem:nightMode' // 夜间模式
| 'menuItem:refresh' // 刷新
| 'menuItem:profile' // 查看公众号(已添加)
| 'menuItem:addContact' // 查看公众号(未添加)
| 'menuItem:share:appMessage' // 发送给朋友
| 'menuItem:share:timeline' // 分享到朋友圈
| 'menuItem:share:qq' // 分享到 QQ
| 'menuItem:share:weiboApp' // 分享到 Weibo
| 'menuItem:favorite' // 收藏
| 'menuItem:share:facebook' // 分享到 Facebook
| 'menuItem:share:QZone' // 分享到 QQ 空间
| 'menuItem:editTag' // 编辑标签
| 'menuItem:delete' // 删除
| 'menuItem:copyUrl' // 复制链接
| 'menuItem:originPage' // 原网页
| 'menuItem:readMode' // 阅读模式
| 'menuItem:openWithQQBrowser' // 在QQ浏览器中打开
| 'menuItem:openWithSafari' // 在Safari中打开
| 'menuItem:share:email' // 邮件
| 'menuItem:share:brand'; // 一些特殊公众号
type scanTypes =
| 'qrCode' // 二维码
| 'barCode'; // 一维码
type ImageSize = 'original' | 'compressed';
type SourceType = 'album' | 'camera';
/** **************************************************************************
* Interface definations
****************************************************************************/
interface ConfigOptions {
/**
* ,api的返回值会在客户端alert出来
* pc端打开log打出pc端时才会打印
*/
debug?: boolean;
/**
*
*/
appId: string;
/**
*
*/
timestamp: string | number;
/**
*
*/
nonceStr: string;
/**
*
*/
signature: string;
/**
* 使JS接口列表
*/
jsApiList: JSApis[];
/* beta */
beta: boolean;
[x: string]: any;
}
/**
* wx对象(使jWeixin对象)
*
*/
interface Callbacks {
/**
*
*/
success?: (res: any) => void;
/**
*
*/
fail?: (res: any) => void;
/**
*
*/
complete?: (res: any) => void;
/**
* api才会用到
*/
cancel?: (res: any) => void;
}
interface MenuCallbacks extends Callbacks {
/**
* Menu中的按钮点击时触发的方法Menu中的相关接口
*/
trigger?: (res: any) => void;
}
interface CheckJsApiOptions extends Callbacks {
/**
* JS接口列表
*/
jsApiList: JSApis[];
}
interface OnMenuShareTimelineOptions extends MenuCallbacks {
/**
*
*/
title: string;
/**
* JS安全域名一致
*/
link: string;
/**
*
*/
imgUrl?: string;
}
interface OnMenuShareAppMessageOptions extends OnMenuShareTimelineOptions {
/**
*
*/
desc?: string;
/**
* ,musicvideo或linklink
*/
type?: 'music' | 'video' | 'link';
/**
* type是music或video
*/
dataUrl?: string;
}
interface OnMenuShareQQ extends OnMenuShareTimelineOptions {
/**
*
*/
desc?: string;
}
interface OnMenuShareWeibo extends OnMenuShareTimelineOptions {
/**
*
*/
desc?: string;
}
interface OnMenuShareQZone extends OnMenuShareTimelineOptions {
/**
*
*/
desc?: string;
}
interface ChooseImageOptions extends Callbacks {
/**
*
*
* 9
*/
count?: number;
/**
*
*/
sizeType?: ImageSize[];
/**
*
*/
sourceType?: SourceType[];
}
interface PreviewImageOptions extends Callbacks {
/**
* http
*/
current: string;
/**
* http
*/
urls: string[];
}
interface UploadImageOptions extends Callbacks {
/**
* IDchooseImage接口获得
*/
localId: string;
/**
*
*/
isShowProgressTips?: boolean;
}
interface DownloadImageOptions extends Callbacks {
/**
* IDuploadImage接口获得
*/
serverId: string;
/**
*
*/
isShowProgressTips?: boolean;
}
interface GetLocalImgDataOptions extends Callbacks {
/**
* localID
*/
localId: string;
}
interface LocalVoiceOptions extends Callbacks {
/**
* ID stopRecord
*/
localId: string;
}
interface UploadVoiceOptions extends LocalVoiceOptions {
/**
*
*/
isShowProgressTips?: boolean;
}
interface DownloadVoiceOptions extends Callbacks {
/**
* IDuploadVoice接口获得
*/
serverId: string;
/**
*
*/
isShowProgressTips?: boolean;
}
interface OpenLocationOptions extends Callbacks {
/**
* 90 ~ -90
*/
latitude: number;
/**
* 180 ~ -180
*/
longitude: number;
/**
*
*/
name: string;
/**
*
*/
address: string;
/**
* ,,1~28
*/
scale?: number;
/**
* ,
*/
infoUrl?: string;
}
interface GetLocationOptions extends Callbacks {
/**
* wgs84的gps坐标openLocation用的火星坐标'gcj02'
*/
type: 'wgs84' | 'gcj02';
}
interface StartSearchBeacons {
/**
* ticket,
*/
ticket: string;
}
interface MenuOptions {
menuList: Menus[];
}
interface ScanQRCodeOptions extends Callbacks {
/**
* 01
*/
needResult?: 0 | 1;
/**
*
*/
scanType?: scanTypes[];
}
interface OpenProductSpecificViewOptions {
/**
* id
*/
productId: string;
/**
* 0.
* 1.
* 2.
*/
viewType: 0 | 1 | 2;
}
interface ChooseCardOptions extends Callbacks {
/**
* Id
*/
shopId?: string;
/**
*
*/
cardType?: string;
/**
* Id
*/
cardId?: string;
/**
*
*/
timestamp: number;
/**
*
*/
nonceStr: string;
/**
* 'SHA1'
*/
signType: 'SHA1';
/**
*
*/
cardSign: string;
}
interface AddCard {
cardId: string;
cardExt: string;
}
interface AddCardOptions extends Callbacks {
cardList: AddCard[];
}
interface OpenCard {
cardId: string;
code: string;
}
interface OpenCardOptions extends Callbacks {
cardList: OpenCard[];
}
interface ChooseWXPayOptions extends Callbacks {
/**
* jssdk中的所有使用timestamp字段均为小写
* 使timeStamp字段名需大写其中的S字符
*/
timestamp: string;
/**
* 32
*/
nonceStr: string;
/**
* prepay_id参数值prepay_id=***
*/
package: string;
/**
* 'SHA1'使'MD5'
*/
signType: 'SHA1' | 'MD5';
/**
*
*/
paySign: string;
}
/** **************************************************************************
*
****************************************************************************/
/**
*
* 使 JS-SDK
* url url SPA web app url变化时进行调用,
* Android pushState H5
* 使 pushState web app
* Android6.2
*/
function config(options: ConfigOptions): void;
/**
*
*
* config信息验证后会执行ready方法config接口获得结果之后
* config是一个客户端的异步操作
* ready函数中调用来确保正确执行
* ready函数中
*/
function ready(callback: () => void): void;
/**
*
*
* config信息验证失败会执行error函数
* config的debug模式查看res参数中查看
* SPA可以在这里更新签名
*/
function error(callback: (res: any) => void): void;
/**
* JS接口
*
* checkJsApi接口是客户端6.0.2
* 使checkJsApi来检测
*/
function checkJsApi(options: CheckJsApiOptions): void;
/** **************************************************************************
*
****************************************************************************/
/**
*
*/
function updateTimelineShareData(options: OnMenuShareTimelineOptions): void;
/**
*
*/
function updateAppMessageShareData(
options: OnMenuShareAppMessageOptions
): void;
/**
*
*/
function onMenuShareTimeline(options: OnMenuShareTimelineOptions): void;
/**
*
*/
function onMenuShareAppMessage(options: OnMenuShareAppMessageOptions): void;
/**
* QQ
*/
function onMenuShareQQ(options: OnMenuShareQQ): void;
/**
*
*/
function onMenuShareWeibo(options: OnMenuShareWeibo): void;
/**
* QQ空间
*/
function onMenuShareQZone(options: OnMenuShareQZone): void;
/** **************************************************************************
*
****************************************************************************/
/**
*
*/
function chooseImage(options: ChooseImageOptions): void;
/**
*
*/
function previewImage(options: PreviewImageOptions): void;
/**
*
*
* 3 serverId media_id
*/
function uploadImage(options: UploadImageOptions): void;
/**
*
*/
function downloadImage(options: DownloadImageOptions): void;
/**
*
*/
function getLocalImgData(options: GetLocalImgDataOptions): void;
/** **************************************************************************
*
****************************************************************************/
/**
*
*/
function startRecord(): void;
/**
*
*/
function stopRecord(options: Callbacks): void;
/**
*
*/
function onVoiceRecordEnd(options: Callbacks): void;
/**
*
*/
function playVoice(options: LocalVoiceOptions): void;
/**
*
*/
function pauseVoice(options: LocalVoiceOptions): void;
/**
*
*/
function stopVoice(options: LocalVoiceOptions): void;
/**
*
*/
function onVoicePlayEnd(options: Callbacks): void;
/**
*
*/
function uploadVoice(options: UploadVoiceOptions): void;
/**
*
*/
function downloadVoice(options: DownloadVoiceOptions): void;
/** **************************************************************************
*
****************************************************************************/
/**
*
*/
function translateVoice(options: UploadVoiceOptions): void;
/** **************************************************************************
*
****************************************************************************/
/**
*
*/
function getNetworkType(options: Callbacks): void;
/** **************************************************************************
*
****************************************************************************/
/**
* 使
*/
function openLocation(options: OpenLocationOptions): void;
/**
*
*/
function getLocation(options: GetLocationOptions): void;
/** **************************************************************************
*
****************************************************************************/
/**
* ibeacon设备接口
*/
function startSearchBeacons(options: StartSearchBeacons): void;
/**
* ibeacon设备接口
*/
function stopSearchBeacons(options: Callbacks): void;
/**
* ibeacon设备接口
*
* 使
*/
function onSearchBeacons(options: Callbacks): void;
/** **************************************************************************
*
****************************************************************************/
/**
*
*/
function closeWindow(): void;
/**
*
*/
function hideMenuItems(options: MenuOptions): void;
/**
*
*/
function showMenuItems(options: MenuOptions): void;
/**
*
*/
function hideAllNonBaseMenuItem(): void;
/**
*
*/
function showAllNonBaseMenuItem(): void;
/** **************************************************************************
*
****************************************************************************/
/**
*
*/
function scanQRCode(options: ScanQRCodeOptions): void;
/** **************************************************************************
*
****************************************************************************/
/**
*
*/
function openProductSpecificView(
options: OpenProductSpecificViewOptions
): void;
/** **************************************************************************
*
****************************************************************************/
/**
*
*/
function chooseCard(options: ChooseCardOptions): void;
/**
*
*/
function addCard(options: AddCardOptions): void;
/**
*
*/
function openCard(options: OpenCardOptions): void;
/** **************************************************************************
*
****************************************************************************/
/**
*
*/
function chooseWXPay(options: ChooseWXPayOptions): void;
}
declare module 'weixin-js-sdk' {
export = WeixinJsSdk;
}