新增feature weiXinJsSdk 来支持jssdk api调用
This commit is contained in:
parent
3bf5d75dad
commit
d406b70579
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}>;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ exports.default = OakComponent({
|
|||
name: '',
|
||||
entityId: '',
|
||||
type: '',
|
||||
isService: false,
|
||||
isService: true,
|
||||
},
|
||||
data: {
|
||||
initialConfig: {},
|
||||
|
|
|
|||
|
|
@ -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: [
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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>;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
export * from './weiXinJsSdk.web';
|
||||
|
|
@ -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);
|
||||
|
|
@ -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>;
|
||||
}
|
||||
|
|
@ -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;
|
||||
|
|
@ -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 {};
|
||||
|
|
@ -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;
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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';
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -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;
|
||||
|
|
@ -12,7 +12,7 @@ export default OakComponent({
|
|||
name: '',
|
||||
entityId: '',
|
||||
type: '',
|
||||
isService: false,
|
||||
isService: true,
|
||||
},
|
||||
data: {
|
||||
initialConfig: {} as Config,
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ export default function render(
|
|||
type,
|
||||
currentConfig,
|
||||
dirty,
|
||||
isService = true,
|
||||
isService,
|
||||
} = props.data;
|
||||
const { resetConfig, updateConfig, setValue, removeItem, cleanKey } =
|
||||
props.methods;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
);
|
||||
}
|
||||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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>;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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('小程序无需该操作');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
|
||||
console.warn('不应该跑到这里');
|
||||
export * from './weiXinJsSdk.web';
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
|
||||
/**
|
||||
* 分享类型,music、video或link,不填默认为link
|
||||
*/
|
||||
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 {
|
||||
/**
|
||||
* 需要上传的图片的本地ID,由chooseImage接口获得
|
||||
*/
|
||||
localId: string;
|
||||
|
||||
/**
|
||||
* 显示进度提示
|
||||
*/
|
||||
isShowProgressTips?: boolean;
|
||||
}
|
||||
|
||||
interface DownloadImageOptions extends Callbacks {
|
||||
/**
|
||||
* 需要下载的图片的服务器端ID,由uploadImage接口获得
|
||||
*/
|
||||
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 {
|
||||
/**
|
||||
* 需要下载的音频的服务器端ID,由uploadVoice接口获得
|
||||
*/
|
||||
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 {
|
||||
/**
|
||||
* 默认为0,扫描结果由微信处理,1则直接返回扫描结果
|
||||
*/
|
||||
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;
|
||||
}
|
||||
Loading…
Reference in New Issue