bill-deploy-bindings 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -0
- package/alipay/runtime/session.js +102 -0
- package/alipay.config.json +4 -0
- package/components.json +1 -0
- package/functions/alipay-miniprogram/exitMiniProgram/binding.mjs +13 -0
- package/functions/alipay-miniprogram/exitMiniProgram/endpoints.mjs +11 -0
- package/functions/alipay-miniprogram/exitMiniProgram/host.mjs +5 -0
- package/functions/alipay-miniprogram/exitMiniProgram/index.d.ts +12 -0
- package/functions/alipay-miniprogram/exitMiniProgram/index.mjs +5 -0
- package/functions/alipay-miniprogram/index.d.ts +7 -0
- package/functions/alipay-miniprogram/index.mjs +4 -0
- package/functions/alipay-miniprogram/payBill/binding.mjs +17 -0
- package/functions/alipay-miniprogram/payBill/endpoints.mjs +26 -0
- package/functions/alipay-miniprogram/payBill/host.mjs +5 -0
- package/functions/alipay-miniprogram/payBill/index.d.ts +12 -0
- package/functions/alipay-miniprogram/payBill/index.mjs +5 -0
- package/functions/alipay-miniprogram/preparePaymentPackets/binding.mjs +18 -0
- package/functions/alipay-miniprogram/preparePaymentPackets/endpoints.mjs +53 -0
- package/functions/alipay-miniprogram/preparePaymentPackets/host.mjs +5 -0
- package/functions/alipay-miniprogram/preparePaymentPackets/index.d.ts +14 -0
- package/functions/alipay-miniprogram/preparePaymentPackets/index.mjs +5 -0
- package/package.json +49 -0
- package/pages/55Sf5rS757y06LS5/5p-l6LSm57uT5p6c/index.d.ts +2 -0
- package/pages/55Sf5rS757y06LS5/5p-l6LSm57uT5p6c/index.js +2 -0
- package/pages/55Sf5rS757y06LS5/5p-l6LSm57uT5p6c/index.mjs +37 -0
- package/pages.json +8 -0
- package/services.json +164 -0
package/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# bill-deploy-bindings
|
|
2
|
+
|
|
3
|
+
安装:npm install bill-deploy-bindings@1.0.4
|
|
4
|
+
|
|
5
|
+
支付宝小程序:将 alipay.config.json 的 usingComponents 与 plugins 合并进应用注册,按组件 index.d.ts 的 inputs 元组顺序提供逻辑值和列出的物理回调;回调名称与交互快照字段取自 callback 中的物理别名(on + 首字母大写),不会翻译逻辑名称;组件内部执行 props 适配属性,输入值更新会立即撤销旧会话,并通过 keyed 原生子组件重新适配;旧组件保存的回调不进入新会话。生成的 session 子目录和 runtime 文件须随包完整交付,不能只复制顶层 index.js。组件模板、实现、样式及外部标签适配均已交付。需在支付宝开发工具与真实插件环境验收。
|
|
6
|
+
|
|
7
|
+
浏览器:import { mount } from 'bill-deploy-bindings/<组件名>',mount(container) 返回 destroy()。
|
|
8
|
+
|
|
9
|
+
发布:npm publish。组件列表见 components.json;failures 列出失败回调及编译器确定的下一分支,页面接手方须在该回调中切换到 target,并卸载失败分支。组件不会解释自然语言条件,也不会自行选择回退目标。
|
|
10
|
+
|
|
11
|
+
## 公开函数
|
|
12
|
+
|
|
13
|
+
完整清单及物理入参/返回合同见 services.json。按运行环境导入,浏览器入口不会装载小程序函数。
|
|
14
|
+
|
|
15
|
+
- alipay-miniprogram: payBill — bill-deploy-bindings/functions/alipay-miniprogram/payBill
|
|
16
|
+
- alipay-miniprogram: preparePaymentPackets — bill-deploy-bindings/functions/alipay-miniprogram/preparePaymentPackets
|
|
17
|
+
- alipay-miniprogram: exitMiniProgram — bill-deploy-bindings/functions/alipay-miniprogram/exitMiniProgram
|
|
18
|
+
|
|
19
|
+
`import {createServices} from 'bill-deploy-bindings/functions/alipay-miniprogram';`
|
|
20
|
+
|
|
21
|
+
`const services = createServices(host); await services.payBill(input);`
|
|
22
|
+
|
|
23
|
+
宿主按端点合同提供 my 与 invokeHttp;每个 createServices 实例独立注入,不设置全局宿主。单函数可从对应 entry 导入 createFunction(host)。函数只接收 execute 物理参数;bind 的逻辑值转换仍由接手方实现。声明 T | void 的中断函数还提供 invokeInterruption(continuation,input),由 continuation 完成交接,不要在无返回退出后继续事务。
|
|
24
|
+
|
|
25
|
+
发布:npm publish。独立函数入口不包含 Mock 或 bind 参考实现。页面会话仅管理宿主提供的初始化工厂返回的页面实例;页面与函数的 bind 都是参考逻辑,不包含在发布代码中。入口见 services.json.pages 与 pages.json。真实设备和外部服务仍需验收。
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
function createPageRegistry(){
|
|
3
|
+
const pages=new WeakMap();
|
|
4
|
+
return {mountPage(owner,anchorId,initialize){
|
|
5
|
+
pages.get(owner)?.session.dispose();
|
|
6
|
+
const session=createPageSession(initialize);pages.set(owner,{anchorId,session});return session;
|
|
7
|
+
},page(component,anchorId){
|
|
8
|
+
const current=pages.get(component.$page);
|
|
9
|
+
if(!current||current.anchorId!==anchorId)throw new Error('当前页面尚未挂载对应的页面绑定');
|
|
10
|
+
return current.session;
|
|
11
|
+
}};
|
|
12
|
+
}
|
|
13
|
+
function createPageSession(initialize) {
|
|
14
|
+
let active=true,value,initialized=false;
|
|
15
|
+
const listeners=new Set();
|
|
16
|
+
const refresh=()=>{if(active&&initialized)for(const listener of [...listeners])listener();};
|
|
17
|
+
const ready=Promise.resolve().then(initialize).then(result=>{
|
|
18
|
+
if(!active)throw new Error('页面已卸载,初始化结果已失效');
|
|
19
|
+
if(!result||typeof result!=='object')throw new Error('页面上下文必须是类实例');
|
|
20
|
+
value=result;initialized=true;
|
|
21
|
+
});
|
|
22
|
+
return {
|
|
23
|
+
ready,
|
|
24
|
+
get active(){return active;},
|
|
25
|
+
get value(){if(!active||!initialized)throw new Error('页面上下文尚未就绪或已经卸载');return value;},
|
|
26
|
+
subscribe(listener){if(!active)throw new Error('页面已经卸载');listeners.add(listener);return ()=>listeners.delete(listener);},
|
|
27
|
+
run(action){
|
|
28
|
+
if(!active||!initialized)throw new Error('页面上下文尚未就绪或已经卸载');
|
|
29
|
+
let result;
|
|
30
|
+
try {result=action(value);}catch(error){refresh();throw error;}
|
|
31
|
+
refresh();
|
|
32
|
+
return result&&typeof result.then==='function'?Promise.resolve(result).finally(refresh):result;
|
|
33
|
+
},
|
|
34
|
+
dispose(){active=false;listeners.clear();value=undefined;}
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
Object.assign(exports,createPageRegistry());
|
|
38
|
+
let sequence=0;
|
|
39
|
+
const leases=new Map(),hosts=new WeakMap(),contexts=new WeakMap(),observed=new WeakMap();
|
|
40
|
+
exports.active=context=>{const state=contexts.get(context);return !!state?.active&&state.lease.active;};
|
|
41
|
+
function retire(owner){
|
|
42
|
+
const lease=hosts.get(owner);if(!lease)return;
|
|
43
|
+
hosts.delete(owner);leases.delete(lease.id);lease.active=false;
|
|
44
|
+
lease.dispose?.();
|
|
45
|
+
}
|
|
46
|
+
exports.host=(defaults,watched,inputCount)=>{
|
|
47
|
+
const snapshot=owner=>{
|
|
48
|
+
const props={...defaults,...owner.props};
|
|
49
|
+
if(inputCount!==null){
|
|
50
|
+
const inputs=props.inputs??[];
|
|
51
|
+
if(!Array.isArray(inputs)||inputs.length!==inputCount)throw new Error('组件 inputs 须提供 '+inputCount+' 个有序逻辑入参');
|
|
52
|
+
props.inputs=[...inputs];
|
|
53
|
+
}
|
|
54
|
+
return props;
|
|
55
|
+
};
|
|
56
|
+
const fingerprint=owner=>JSON.stringify(watched.map(key=>owner.props[key]));
|
|
57
|
+
const replace=owner=>{
|
|
58
|
+
observed.set(owner,fingerprint(owner));
|
|
59
|
+
retire(owner);
|
|
60
|
+
try{
|
|
61
|
+
const props=snapshot(owner),lease={id:String(++sequence),active:true,props,dispose:null};
|
|
62
|
+
hosts.set(owner,lease);leases.set(lease.id,lease);
|
|
63
|
+
owner.setData({sessions:[{id:lease.id}]});
|
|
64
|
+
}catch(error){retire(owner);owner.setData({sessions:[]});throw error;}
|
|
65
|
+
};
|
|
66
|
+
return {props:defaults,data:{sessions:[]},didMount(){replace(this);},didUpdate(){
|
|
67
|
+
const lease=hosts.get(this);if(!lease){if(observed.get(this)!==fingerprint(this))replace(this);return;}
|
|
68
|
+
let next;try{next=snapshot(this);}catch(error){observed.set(this,fingerprint(this));retire(this);this.setData({sessions:[]});throw error;}
|
|
69
|
+
const changed=observed.get(this)!==fingerprint(this);
|
|
70
|
+
if(changed)replace(this);else lease.props=next;
|
|
71
|
+
},didUnmount(){retire(this);}};
|
|
72
|
+
};
|
|
73
|
+
exports.isolate=definition=>{
|
|
74
|
+
const instances=new WeakMap();
|
|
75
|
+
const dispose=instance=>{
|
|
76
|
+
const state=instances.get(instance);if(!state||!state.active)return;
|
|
77
|
+
state.active=false;state.cleaning=true;state.lease.dispose=null;
|
|
78
|
+
try{return definition.didUnmount?.call(state.context);}finally{state.cleaning=false;}
|
|
79
|
+
};
|
|
80
|
+
const methods=Object.fromEntries(Object.entries(definition.methods||{}).map(([name,method])=>[name,function(...args){
|
|
81
|
+
const state=instances.get(this);if(!state?.active||!state.lease.active)return;
|
|
82
|
+
return method.apply(state.context,args);
|
|
83
|
+
}]));
|
|
84
|
+
return {...definition,props:{leaseId:null},methods,didMount(){
|
|
85
|
+
const lease=leases.get(this.props.leaseId);if(!lease?.active)return;
|
|
86
|
+
const context=Object.create(this),state={lease,context,active:true,cleaning:false};
|
|
87
|
+
Object.defineProperties(context,{props:{get:()=>lease.props},data:{get:()=>this.data},setData:{value:(values,done)=>{
|
|
88
|
+
if(state.active&&lease.active||state.cleaning)this.setData(values,()=>{if(state.active&&lease.active)done?.();});
|
|
89
|
+
}}});
|
|
90
|
+
for(const [name,method] of Object.entries(definition.methods||{}))context[name]=(...args)=>{
|
|
91
|
+
if(state.active&&lease.active)return method.apply(context,args);
|
|
92
|
+
};
|
|
93
|
+
instances.set(this,state);contexts.set(context,state);lease.dispose=()=>dispose(this);
|
|
94
|
+
try{
|
|
95
|
+
this.setData(JSON.parse(JSON.stringify(definition.data||{})));
|
|
96
|
+
const result=definition.didMount?.call(context);
|
|
97
|
+
return result&&typeof result.then==='function'?result.catch(error=>{dispose(this);throw error;}):result;
|
|
98
|
+
}catch(error){dispose(this);throw error;}
|
|
99
|
+
},didUpdate(previous,data){
|
|
100
|
+
const state=instances.get(this);if(state?.active&&state.lease.active)return definition.didUpdate?.call(state.context,state.lease.props,data);
|
|
101
|
+
},didUnmount(){return dispose(this);}};
|
|
102
|
+
};
|
package/components.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
[]
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
function createBinding(endpoints) {
|
|
2
|
+
"use strict";
|
|
3
|
+
const execute = (({exitMiniProgram}) => {
|
|
4
|
+
// 仅派发退出请求,无完成回调;空返回不表示小程序已经关闭。
|
|
5
|
+
async function execute() {
|
|
6
|
+
exitMiniProgram();
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
return execute;
|
|
10
|
+
})(endpoints);
|
|
11
|
+
return {execute: input => execute()};
|
|
12
|
+
}
|
|
13
|
+
export {createBinding};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
declare const my: {
|
|
2
|
+
call<T>(api: string, request: object, success: (response: T) => void, failure?: (error: Error) => void): void;
|
|
3
|
+
call(api: string, request: object): void;
|
|
4
|
+
};
|
|
5
|
+
declare function invokeHttp<T>(url: string, request: {method: string; headers?: Record<string,string | "">; body?: string | ""}): Promise<T>;
|
|
6
|
+
|
|
7
|
+
export interface BindingHost {my?:typeof my;invokeHttp?:typeof invokeHttp}
|
|
8
|
+
interface Value0 {}
|
|
9
|
+
export interface Input {}
|
|
10
|
+
export type Output = void;
|
|
11
|
+
export interface Service { (input:Input):Promise<Output>;}
|
|
12
|
+
export declare function createFunction(host:BindingHost):Service;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type {Service as Service0} from './payBill/index.js';
|
|
2
|
+
import type {Service as Service1} from './preparePaymentPackets/index.js';
|
|
3
|
+
import type {Service as Service2} from './exitMiniProgram/index.js';
|
|
4
|
+
export type {BindingHost} from './payBill/index.js';
|
|
5
|
+
import type {BindingHost} from './payBill/index.js';
|
|
6
|
+
export interface Services {"payBill":Service0;"preparePaymentPackets":Service1;"exitMiniProgram":Service2}
|
|
7
|
+
export declare function createServices(host:BindingHost):Readonly<Services>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import {createFunction as create0} from './payBill/index.mjs';
|
|
2
|
+
import {createFunction as create1} from './preparePaymentPackets/index.mjs';
|
|
3
|
+
import {createFunction as create2} from './exitMiniProgram/index.mjs';
|
|
4
|
+
export function createServices(host) {return Object.freeze({["payBill"]:create0(host),["preparePaymentPackets"]:create1(host),["exitMiniProgram"]:create2(host)});}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
function createBinding(endpoints) {
|
|
2
|
+
"use strict";
|
|
3
|
+
const execute = (({openCashier,openPaymentBillList}) => {
|
|
4
|
+
async function execute(billNo, tradeNo) {
|
|
5
|
+
const outcome = await openCashier(billNo, tradeNo);
|
|
6
|
+
if (outcome === "pending") {
|
|
7
|
+
await openPaymentBillList();
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
return outcome === "paid" ? "支付成功" : "支付未完成";
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return execute;
|
|
14
|
+
})(endpoints);
|
|
15
|
+
return {execute: input => execute(input["billNo"], input["tradeNo"]), async invokeInterruption(continuation, input) { continuation.completeBinding(await execute(input["billNo"], input["tradeNo"]), {allowExit:true}); }};
|
|
16
|
+
}
|
|
17
|
+
export {createBinding};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
|
|
2
|
+
const packages={};
|
|
3
|
+
export function createEndpoints(host) {
|
|
4
|
+
const openCashier=(({my,invokeHttp}, {})=>{
|
|
5
|
+
async function openCashier(billNo, tradeNo) {
|
|
6
|
+
const request = tradeNo ? { tradeNO: tradeNo } : { tradeNO: billNo, bizType: "trade", bizSubType: "puc_charge" };
|
|
7
|
+
const response = await new Promise((resolve, reject) => my.call("tradePay", request, resolve, reject));
|
|
8
|
+
if (typeof response !== "object" || response === null) {
|
|
9
|
+
throw new Error("收银台返回缺少 resultCode");
|
|
10
|
+
}
|
|
11
|
+
const raw = response.resultCode;
|
|
12
|
+
const code = typeof raw === "number" && Number.isSafeInteger(raw) && raw >= 0 ? String(raw) : raw;
|
|
13
|
+
if (typeof code !== "string" || code === "")
|
|
14
|
+
throw new Error("收银台 resultCode 必须是非空字符串或非负安全整数");
|
|
15
|
+
return code === "9000" ? "paid" : code === "8000" ? "pending" : "unfinished";
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return openCashier;})(host, {});
|
|
19
|
+
const openPaymentBillList=(({my,invokeHttp}, {})=>{
|
|
20
|
+
async function openPaymentBillList() {
|
|
21
|
+
my.call("startApp", { appId: "20000003", param: { returnHome: "NO", actionType: "toBillList", category: "PUC_CHARGE" }, closeSelfWindow: true });
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return openPaymentBillList;})(host, {});
|
|
25
|
+
return {openCashier,openPaymentBillList};
|
|
26
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
declare const my: {
|
|
2
|
+
call<T>(api: string, request: object, success: (response: T) => void, failure?: (error: Error) => void): void;
|
|
3
|
+
call(api: string, request: object): void;
|
|
4
|
+
};
|
|
5
|
+
declare function invokeHttp<T>(url: string, request: {method: string; headers?: Record<string,string | "">; body?: string | ""}): Promise<T>;
|
|
6
|
+
|
|
7
|
+
export interface BindingHost {my?:typeof my;invokeHttp?:typeof invokeHttp}
|
|
8
|
+
interface Value0 {"billNo":string;"tradeNo":string|null}
|
|
9
|
+
export interface Input {"billNo":string;"tradeNo":string|null}
|
|
10
|
+
export type Output = "支付成功"|"支付未完成"|void;
|
|
11
|
+
export interface Service { (input:Input):Promise<Output>;invokeInterruption(continuation:{completeBinding(value:Output,options:{allowExit:true}):unknown},input:Input):Promise<void>;}
|
|
12
|
+
export declare function createFunction(host:BindingHost):Service;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
function createBinding(endpoints) {
|
|
2
|
+
"use strict";
|
|
3
|
+
const execute = (({claimPacket,queryPendingPackets,queryWalletPackets}) => {
|
|
4
|
+
async function execute(templateIds) {
|
|
5
|
+
try {
|
|
6
|
+
const contentId = await queryPendingPackets();
|
|
7
|
+
if (contentId)
|
|
8
|
+
await claimPacket(contentId);
|
|
9
|
+
}
|
|
10
|
+
catch { /* 候选或领取不可用时仍查询实际卡包。 */ }
|
|
11
|
+
return await queryWalletPackets(templateIds);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return execute;
|
|
15
|
+
})(endpoints);
|
|
16
|
+
return {execute: input => execute(input["templateIds"])};
|
|
17
|
+
}
|
|
18
|
+
export {createBinding};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
|
|
2
|
+
const packages={};
|
|
3
|
+
export function createEndpoints(host) {
|
|
4
|
+
const claimPacket=(({my,invokeHttp}, {})=>{
|
|
5
|
+
async function claimPacket(contentId) {
|
|
6
|
+
const requestData = [{ scene: "jiaofei", touchPoint: "livingPaymentHomePage", booth: "jiaofeiIndexRedPacket", needRecordInfo: true, contentId }];
|
|
7
|
+
await new Promise((resolve, reject) => my.call("rpc", { requestData, operationType: "alipay.imasp.scene.userapply" }, resolve, reject));
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
return claimPacket;})(host, {});
|
|
11
|
+
const queryPendingPackets=(({my,invokeHttp}, {})=>{
|
|
12
|
+
async function queryPendingPackets() {
|
|
13
|
+
const requestData = [{ scene: "jiaofei", touchPoint: "livingPaymentHomePage", booth: "jiaofeiIndexRedPacket" }];
|
|
14
|
+
const result = await new Promise((resolve, reject) => my.call("rpc", { requestData, operationType: "alipay.imasp.scene.contentQuery" }, resolve, reject));
|
|
15
|
+
const first = result.success ? (result.contentInfos?.jiaofeiIndexRedPacket || []).find(row => row.status === "noReceive") : undefined;
|
|
16
|
+
return first?.contentId || null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return queryPendingPackets;})(host, {});
|
|
20
|
+
const queryWalletPackets=(({my,invokeHttp}, {})=>{
|
|
21
|
+
async function queryWalletPackets(templateIds) {
|
|
22
|
+
let wallet;
|
|
23
|
+
try {
|
|
24
|
+
wallet = await new Promise((resolve, reject) => my.call("rpc", { operationType: "alipay.asset.voucher.voucherlist.query", requestData: [{ pageNum: 1, pageSize: 100, bizCodes: ["ALIPAY_FEE", "JF_DEDUCT"], statusList: ["ENABLED"],
|
|
25
|
+
productCodes: ["ALIPAY_FIX_CASH_VOUCHER", "ALIPAY_FIX_CASH_VOUCHER_POINT", "ALIPAY_FIX_CASH_VOUCHER_POINT", "COUPON"] }] }, resolve, reject));
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return { packets: [], outcome: "unavailable" };
|
|
29
|
+
}
|
|
30
|
+
if (!wallet.success)
|
|
31
|
+
return { packets: [], outcome: "unavailable" };
|
|
32
|
+
return { outcome: "success", packets: (wallet.voucherMgwDTOList || []).filter(row => row.available !== "false").map(row => {
|
|
33
|
+
if (typeof row.availableAmount !== "string" || !row.availableAmount.trim()) {
|
|
34
|
+
throw new Error("红包回调缺少有效金额");
|
|
35
|
+
}
|
|
36
|
+
if (typeof row.gmtExpired !== "number" || !Number.isFinite(row.gmtExpired)) {
|
|
37
|
+
throw new Error("红包回调缺少有效到期时间");
|
|
38
|
+
}
|
|
39
|
+
const amount = row.availableAmount.trim();
|
|
40
|
+
const expiresOn = new Date(Math.trunc(row.gmtExpired) + 28800000).toISOString().slice(0, 10);
|
|
41
|
+
if (!amount || !expiresOn)
|
|
42
|
+
throw new Error("红包回调缺少金额或到期日期");
|
|
43
|
+
return {
|
|
44
|
+
name: row.name || "生活缴费红包", amount,
|
|
45
|
+
expiresOn,
|
|
46
|
+
matchesInstitution: !!row.templateId && templateIds.includes(row.templateId)
|
|
47
|
+
};
|
|
48
|
+
}) };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return queryWalletPackets;})(host, {});
|
|
52
|
+
return {claimPacket,queryPendingPackets,queryWalletPackets};
|
|
53
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
declare const my: {
|
|
2
|
+
call<T>(api: string, request: object, success: (response: T) => void, failure?: (error: Error) => void): void;
|
|
3
|
+
call(api: string, request: object): void;
|
|
4
|
+
};
|
|
5
|
+
declare function invokeHttp<T>(url: string, request: {method: string; headers?: Record<string,string | "">; body?: string | ""}): Promise<T>;
|
|
6
|
+
|
|
7
|
+
export interface BindingHost {my?:typeof my;invokeHttp?:typeof invokeHttp}
|
|
8
|
+
interface Value0 {"packets":Array<Value1>;"outcome":"success"|"unavailable"}
|
|
9
|
+
interface Value1 {"name":string;"amount":string;"expiresOn":string;"matchesInstitution":boolean}
|
|
10
|
+
interface Value2 {"templateIds":Array<string>}
|
|
11
|
+
export interface Input {"templateIds":Array<string>}
|
|
12
|
+
export type Output = Value0;
|
|
13
|
+
export interface Service { (input:Input):Promise<Output>;}
|
|
14
|
+
export declare function createFunction(host:BindingHost):Service;
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "bill-deploy-bindings",
|
|
3
|
+
"version": "1.0.4",
|
|
4
|
+
"description": "bill-deploy compiled physical bindings",
|
|
5
|
+
"exports": {
|
|
6
|
+
"./pages/55Sf5rS757y06LS5/5p-l6LSm57uT5p6c": {
|
|
7
|
+
"types": "./pages/55Sf5rS757y06LS5/5p-l6LSm57uT5p6c/index.d.ts",
|
|
8
|
+
"import": "./pages/55Sf5rS757y06LS5/5p-l6LSm57uT5p6c/index.mjs",
|
|
9
|
+
"default": "./pages/55Sf5rS757y06LS5/5p-l6LSm57uT5p6c/index.js"
|
|
10
|
+
},
|
|
11
|
+
"./alipay/*": "./alipay/*",
|
|
12
|
+
"./alipay.config.json": "./alipay.config.json",
|
|
13
|
+
"./components.json": "./components.json",
|
|
14
|
+
"./pages.json": "./pages.json",
|
|
15
|
+
"./functions/alipay-miniprogram/payBill": {
|
|
16
|
+
"types": "./functions/alipay-miniprogram/payBill/index.d.ts",
|
|
17
|
+
"import": "./functions/alipay-miniprogram/payBill/index.mjs",
|
|
18
|
+
"default": "./functions/alipay-miniprogram/payBill/index.mjs"
|
|
19
|
+
},
|
|
20
|
+
"./functions/alipay-miniprogram/preparePaymentPackets": {
|
|
21
|
+
"types": "./functions/alipay-miniprogram/preparePaymentPackets/index.d.ts",
|
|
22
|
+
"import": "./functions/alipay-miniprogram/preparePaymentPackets/index.mjs",
|
|
23
|
+
"default": "./functions/alipay-miniprogram/preparePaymentPackets/index.mjs"
|
|
24
|
+
},
|
|
25
|
+
"./functions/alipay-miniprogram/exitMiniProgram": {
|
|
26
|
+
"types": "./functions/alipay-miniprogram/exitMiniProgram/index.d.ts",
|
|
27
|
+
"import": "./functions/alipay-miniprogram/exitMiniProgram/index.mjs",
|
|
28
|
+
"default": "./functions/alipay-miniprogram/exitMiniProgram/index.mjs"
|
|
29
|
+
},
|
|
30
|
+
"./functions/alipay-miniprogram": {
|
|
31
|
+
"types": "./functions/alipay-miniprogram/index.d.ts",
|
|
32
|
+
"import": "./functions/alipay-miniprogram/index.mjs",
|
|
33
|
+
"default": "./functions/alipay-miniprogram/index.mjs"
|
|
34
|
+
},
|
|
35
|
+
"./services.json": "./services.json"
|
|
36
|
+
},
|
|
37
|
+
"files": [
|
|
38
|
+
"functions",
|
|
39
|
+
"alipay",
|
|
40
|
+
"browser",
|
|
41
|
+
"pages",
|
|
42
|
+
"pages.json",
|
|
43
|
+
"components.json",
|
|
44
|
+
"alipay.config.json",
|
|
45
|
+
"services.json",
|
|
46
|
+
"README.md"
|
|
47
|
+
],
|
|
48
|
+
"dependencies": {}
|
|
49
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export interface PageSession<T extends object> {readonly ready:Promise<void>; readonly active:boolean; readonly value:T; run<R>(action:(page:T)=>R):R; subscribe(listener:()=>void):()=>void; dispose():void}
|
|
2
|
+
export declare function mountPage<T extends object>(owner:object,initialize:()=>T|Promise<T>):PageSession<T>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
function createPageRegistry(){
|
|
2
|
+
const pages=new WeakMap();
|
|
3
|
+
return {mountPage(owner,anchorId,initialize){
|
|
4
|
+
pages.get(owner)?.session.dispose();
|
|
5
|
+
const session=createPageSession(initialize);pages.set(owner,{anchorId,session});return session;
|
|
6
|
+
},page(component,anchorId){
|
|
7
|
+
const current=pages.get(component.$page);
|
|
8
|
+
if(!current||current.anchorId!==anchorId)throw new Error('当前页面尚未挂载对应的页面绑定');
|
|
9
|
+
return current.session;
|
|
10
|
+
}};
|
|
11
|
+
}
|
|
12
|
+
function createPageSession(initialize) {
|
|
13
|
+
let active=true,value,initialized=false;
|
|
14
|
+
const listeners=new Set();
|
|
15
|
+
const refresh=()=>{if(active&&initialized)for(const listener of [...listeners])listener();};
|
|
16
|
+
const ready=Promise.resolve().then(initialize).then(result=>{
|
|
17
|
+
if(!active)throw new Error('页面已卸载,初始化结果已失效');
|
|
18
|
+
if(!result||typeof result!=='object')throw new Error('页面上下文必须是类实例');
|
|
19
|
+
value=result;initialized=true;
|
|
20
|
+
});
|
|
21
|
+
return {
|
|
22
|
+
ready,
|
|
23
|
+
get active(){return active;},
|
|
24
|
+
get value(){if(!active||!initialized)throw new Error('页面上下文尚未就绪或已经卸载');return value;},
|
|
25
|
+
subscribe(listener){if(!active)throw new Error('页面已经卸载');listeners.add(listener);return ()=>listeners.delete(listener);},
|
|
26
|
+
run(action){
|
|
27
|
+
if(!active||!initialized)throw new Error('页面上下文尚未就绪或已经卸载');
|
|
28
|
+
let result;
|
|
29
|
+
try {result=action(value);}catch(error){refresh();throw error;}
|
|
30
|
+
refresh();
|
|
31
|
+
return result&&typeof result.then==='function'?Promise.resolve(result).finally(refresh):result;
|
|
32
|
+
},
|
|
33
|
+
dispose(){active=false;listeners.clear();value=undefined;}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
const runtime=createPageRegistry();
|
|
37
|
+
export const mountPage=(owner,initialize)=>runtime.mountPage(owner,"{\"视觉稿\":\"查账结果\"}",initialize);
|
package/pages.json
ADDED
package/services.json
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schemaVersion": 1,
|
|
3
|
+
"app": "bill-deploy",
|
|
4
|
+
"package": "bill-deploy-bindings",
|
|
5
|
+
"release": "1.0.4",
|
|
6
|
+
"functions": [
|
|
7
|
+
{
|
|
8
|
+
"name": "payBill",
|
|
9
|
+
"runtime": "alipay-miniprogram",
|
|
10
|
+
"domain": "生活缴费",
|
|
11
|
+
"anchors": [
|
|
12
|
+
"{\"视觉稿\":\"查账结果\",\"组件\":\"立即缴费\",\"事务图\":\"缴费\",\"中断\":\"支付\"}"
|
|
13
|
+
],
|
|
14
|
+
"entry": "bill-deploy-bindings/functions/alipay-miniprogram/payBill",
|
|
15
|
+
"parameters": [
|
|
16
|
+
{
|
|
17
|
+
"name": "billNo",
|
|
18
|
+
"type": "字符串"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"name": "tradeNo",
|
|
22
|
+
"type": "字符串",
|
|
23
|
+
"nullable": true
|
|
24
|
+
}
|
|
25
|
+
],
|
|
26
|
+
"response": "字符串",
|
|
27
|
+
"responseNullable": false,
|
|
28
|
+
"responseMayExit": true,
|
|
29
|
+
"responseValues": [
|
|
30
|
+
"支付成功",
|
|
31
|
+
"支付未完成"
|
|
32
|
+
],
|
|
33
|
+
"types": [
|
|
34
|
+
{
|
|
35
|
+
"name": "ExecuteInput",
|
|
36
|
+
"fields": [
|
|
37
|
+
{
|
|
38
|
+
"name": "billNo",
|
|
39
|
+
"type": "字符串"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"name": "tradeNo",
|
|
43
|
+
"type": "字符串",
|
|
44
|
+
"nullable": true
|
|
45
|
+
}
|
|
46
|
+
]
|
|
47
|
+
}
|
|
48
|
+
]
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"name": "preparePaymentPackets",
|
|
52
|
+
"runtime": "alipay-miniprogram",
|
|
53
|
+
"domain": "生活缴费",
|
|
54
|
+
"anchors": [
|
|
55
|
+
"{\"视觉稿\":\"查账结果\",\"实体\":\"缴费红包\",\"引用\":[\"@本次匹配红包\",\"@第二个匹配红包\"]}"
|
|
56
|
+
],
|
|
57
|
+
"entry": "bill-deploy-bindings/functions/alipay-miniprogram/preparePaymentPackets",
|
|
58
|
+
"parameters": [
|
|
59
|
+
{
|
|
60
|
+
"name": "templateIds",
|
|
61
|
+
"type": "数组<字符串>"
|
|
62
|
+
}
|
|
63
|
+
],
|
|
64
|
+
"response": "PacketResult",
|
|
65
|
+
"responseNullable": false,
|
|
66
|
+
"responseMayExit": false,
|
|
67
|
+
"types": [
|
|
68
|
+
{
|
|
69
|
+
"name": "PacketResult",
|
|
70
|
+
"fields": [
|
|
71
|
+
{
|
|
72
|
+
"name": "packets",
|
|
73
|
+
"type": "数组<Packet>"
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
"name": "outcome",
|
|
77
|
+
"type": "字符串",
|
|
78
|
+
"values": [
|
|
79
|
+
"success",
|
|
80
|
+
"unavailable"
|
|
81
|
+
]
|
|
82
|
+
}
|
|
83
|
+
]
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
"name": "Packet",
|
|
87
|
+
"fields": [
|
|
88
|
+
{
|
|
89
|
+
"name": "name",
|
|
90
|
+
"type": "字符串"
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
"name": "amount",
|
|
94
|
+
"type": "字符串"
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
"name": "expiresOn",
|
|
98
|
+
"type": "字符串"
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
"name": "matchesInstitution",
|
|
102
|
+
"type": "布尔"
|
|
103
|
+
}
|
|
104
|
+
]
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
"name": "ExecuteInput",
|
|
108
|
+
"fields": [
|
|
109
|
+
{
|
|
110
|
+
"name": "templateIds",
|
|
111
|
+
"type": "数组<字符串>"
|
|
112
|
+
}
|
|
113
|
+
]
|
|
114
|
+
}
|
|
115
|
+
]
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
"name": "exitMiniProgram",
|
|
119
|
+
"runtime": "alipay-miniprogram",
|
|
120
|
+
"domain": "生活缴费",
|
|
121
|
+
"anchors": [
|
|
122
|
+
"{\"视觉稿\":\"查账结果\",\"组件\":\"返回\",\"交互\":\"退出当前小程序\"}"
|
|
123
|
+
],
|
|
124
|
+
"entry": "bill-deploy-bindings/functions/alipay-miniprogram/exitMiniProgram",
|
|
125
|
+
"parameters": [],
|
|
126
|
+
"response": "void",
|
|
127
|
+
"responseNullable": false,
|
|
128
|
+
"responseMayExit": false,
|
|
129
|
+
"types": [
|
|
130
|
+
{
|
|
131
|
+
"name": "ExecuteInput",
|
|
132
|
+
"fields": []
|
|
133
|
+
}
|
|
134
|
+
]
|
|
135
|
+
}
|
|
136
|
+
],
|
|
137
|
+
"components": [],
|
|
138
|
+
"pages": [
|
|
139
|
+
{
|
|
140
|
+
"domain": "生活缴费",
|
|
141
|
+
"anchorId": "{\"视觉稿\":\"查账结果\"}",
|
|
142
|
+
"path": "pages/55Sf5rS757y06LS5/5p-l6LSm57uT5p6c",
|
|
143
|
+
"runtime": "host"
|
|
144
|
+
}
|
|
145
|
+
],
|
|
146
|
+
"excluded": [
|
|
147
|
+
{
|
|
148
|
+
"domain": "生活缴费",
|
|
149
|
+
"anchors": [
|
|
150
|
+
"{\"视觉稿\":\"查账结果\"}"
|
|
151
|
+
],
|
|
152
|
+
"name": "queryBillPage",
|
|
153
|
+
"target": "grpc-java"
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
"domain": "生活缴费",
|
|
157
|
+
"anchors": [
|
|
158
|
+
"{\"事务图\":\"缴费\",\"节点\":\"创建待支付缴费单\",\"引用\":\"@本次缴费单\"}"
|
|
159
|
+
],
|
|
160
|
+
"name": "createPaymentOrder",
|
|
161
|
+
"target": "grpc-java"
|
|
162
|
+
}
|
|
163
|
+
]
|
|
164
|
+
}
|