efront 3.21.6 → 3.22.2

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.
@@ -5,12 +5,15 @@
5
5
  var id = params.out_trade_no;
6
6
 
7
7
  var data = await _runtask("couchdb", "get", `alipay-log/${id}`);
8
- await _runtask("couchdb", "put", `alipay-log/${id}?_rev=${data._rev}`, extend(data, {
8
+ extend(data, {
9
9
  alipay_trade_no: params.trade_no,
10
10
  seller_id: params.seller_id,
11
11
  return_amount: params.total_amount,
12
- return_time: new Date().toISOString(),
13
- }));
12
+ trade_status: params.trade_status
13
+ });
14
+ if (req.headers["user-agent"]) data.return_time = new Date().toISOString();
15
+ else data.notify_time = new Date().toISOString();
16
+ await _runtask("couchdb", "put", `alipay-log/${id}?_rev=${data._rev}`, data);
14
17
  context.id = params.out_trade_no;
15
18
  </script>
16
19
  <script>
@@ -18,6 +21,6 @@
18
21
  if (id) parent.postMessage(id);
19
22
  </script>
20
23
  <script serverside>
21
- if(context.id)return `<body style="color:green">支付完成</body>`;
24
+ if (context.id) return `<body style="color:green">支付完成</body>`;
22
25
  else return `<body style="color:red">支付失败</body>`
23
- </script>
26
+ </script>
@@ -0,0 +1,15 @@
1
+ <script serverside>
2
+ var time = Date.now();
3
+ var out_trade_no = encode62.timedecode(request.id);
4
+ var payed = /^(TRADE_FINISHED|TRADE_SUCCESS)$/i;
5
+ for (var cx = 0, dx = 10; cx < dx; cx++) {
6
+ if (Date.now() - time > 30000) return;
7
+ var data = await _runtask("couchdb", 'get', `alipay-log/${out_trade_no}`);
8
+ if (data.return_time || data.notify_time || payed.test(data.trade_status)) return JSON.stringify(data);
9
+ var data1 = await _runtask("alipay-query", out_trade_no);
10
+ if (payed.test(data1.trade_status)) {
11
+ return JSON.stringify(Object.assign(data, { trade_status: data1.trade_status }));
12
+ }
13
+ await new Promise(ok => setTimeout(ok, 300));
14
+ }
15
+ </script>
@@ -50,18 +50,13 @@ ACQ.MERCHANT_PERM_RECEIPT_DAY_LIMIT 超过单日累计收款额度 联系支付
50
50
  if (a < 10) return "0" + a;
51
51
  return a;
52
52
  }
53
- var now = new Date();
54
- function createStamp(now) {
55
- var d = now;
56
- return [d.getFullYear(), d.getMonth() + 1, d.getDate()].map(pad).join("-") +
57
- " " + [d.getHours(), d.getMinutes(), d.getSeconds()].map(pad).join(":");
58
- }
59
53
  var amount = request.id;
60
54
  if (!/^(\d+)(\.\d+)?$/.test(amount)) amount = encode62.timedecode(request.id);
61
55
  var [amount, subject = '网页扫码支付'] = amount.split(',');
56
+ var trade_no = createId();
62
57
  if (!+amount) return forbidden("参数异常");
63
58
  var biz_content = {
64
- out_trade_no: "alipay-" + createId(),
59
+ out_trade_no: "alipay-" + trade_no,
65
60
  product_code: 'FAST_INSTANT_TRADE_PAY',
66
61
  total_amount: amount,
67
62
  qr_pay_mode: 4,
@@ -70,7 +65,6 @@ ACQ.MERCHANT_PERM_RECEIPT_DAY_LIMIT 超过单日累计收款额度 联系支付
70
65
  body: subject,
71
66
  };
72
67
  var params = {
73
- timestamp: createStamp(now),
74
68
  method: "alipay.trade.page.pay",
75
69
  app_id: "2021002143612677",
76
70
  sign_type: "RSA2",
@@ -79,6 +73,7 @@ ACQ.MERCHANT_PERM_RECEIPT_DAY_LIMIT 超过单日累计收款额度 联系支付
79
73
  return_url: `${req.protocol}//${req.headers[":authority"] || req.headers.host}${req.url.replace(/[\.\:][\s\S]*$/, '')}-callback`,
80
74
  biz_content: JSON.stringify(biz_content)
81
75
  };
76
+ params.notify_url = params.return_url;
82
77
  await _runtask("alipay-sign", params);
83
78
 
84
79
  var log = await _runtask("couchdb", "put", "alipay-log/" + biz_content.out_trade_no, {
@@ -89,11 +84,13 @@ ACQ.MERCHANT_PERM_RECEIPT_DAY_LIMIT 超过单日累计收款额度 联系支付
89
84
  subject: biz_content.subject,
90
85
  body: biz_content.body,
91
86
  timestamp: params.timestamp,
92
- create_time: now.toISOString(),
87
+ create_time: new Date().toISOString(),
93
88
  return_url: biz_content.return_url
94
89
  });
95
- res.writeHead(302, {
96
- Location: "https://openapi.alipay.com/gateway.do?" + serialize(params)
97
- });
98
- res.end();
90
+ context.id = biz_content.out_trade_no;
91
+ context.location = "https://openapi.alipay.com/gateway.do?" + serialize(params);
92
+ </script>
93
+ <script>
94
+ parent.postMessage(<%JSON.stringify(context.id)%>);
95
+ location.href = <%JSON.stringify(context.location)%>;
99
96
  </script>
@@ -1,13 +1,14 @@
1
1
  var pay = frame$payment([
2
2
  {
3
3
  url: './alipay:',
4
+ query: './alipay-query:',
4
5
  name: '支付宝',
5
6
  icon: 'alipay.ico',
6
7
  cost(price) {
7
8
  return BigNumber.prd((0.6036218 + 0.204081632) / 100, price);
8
9
  },
9
10
  }
10
- ], 1.00, '支付宝支付测试');
11
+ ], 0.01, '支付宝支付测试');
11
12
  popup(pay, true);
12
13
  console.log(pay)
13
14
  care(pay, 'payment', function (a) {
@@ -72,10 +72,10 @@ class BigNumber {
72
72
  return fixde(numstr, 0, 4);
73
73
  }
74
74
  static ceil(numstr) {
75
- return fixde(numstr, 0, 0);
75
+ return fixde(numstr, 0, /^\-/.test(numstr) ? 9 : 0);
76
76
  }
77
77
  static floor(numstr) {
78
- return fixde(numstr, 0, 9);
78
+ return fixde(numstr, 0, /^\-/.test(numstr) ? 0 : 9);
79
79
  }
80
80
  static fix(numstr, fractionDigits) {
81
81
  fractionDigits = +fractionDigits || 0;
@@ -42,11 +42,16 @@ assert(BigNumber.fix(0.00807703432, 2), '0.01');
42
42
  assert(BigNumber.round(2.2349), '2');
43
43
  assert(BigNumber.round(2.4999), '2');
44
44
  assert(BigNumber.round(2.5000), '3');
45
+ assert(BigNumber.round(-2.5000), '-3');
45
46
  assert(BigNumber.round(2.5100), '3');
46
47
  assert(BigNumber.ceil(2.5100), '3');
48
+ assert(BigNumber.ceil(-2.5100), '-2');
47
49
  assert(BigNumber.ceil(2.000), '2');
50
+ assert(BigNumber.ceil(-2.000), '-2');
48
51
  assert(BigNumber.floor(2.000), '2');
52
+ assert(BigNumber.floor(-2.000), '-2');
49
53
  assert(BigNumber.floor(2.999), '2');
54
+ assert(BigNumber.floor(-2.999), '-3');
50
55
  assert(BigNumber.ceil(2.001), '3');
51
56
  assert(BigNumber.ceil(2.999), '3');
52
57
  assert(BigNumber.fix("9007199254740992.234", 6), '9007199254740992.234000');
@@ -287,6 +287,17 @@ class Program extends Array {
287
287
  }
288
288
  }
289
289
 
290
+ var isShortMethodEnd = function (o) {
291
+ if (!o) return false;
292
+ if (o.type !== SCOPED || o.entry !== "{") return false;
293
+ o = o.prev;
294
+ if (!o) return false;
295
+ if (o.type !== SCOPED || o.entry !== "(") return false;
296
+ o = o.prev;
297
+ if (!o) return false;
298
+ return o.type === PROPERTY;
299
+ };
300
+
290
301
  class Javascript {
291
302
  quotes = [
292
303
  [/'/, /'/, /\\[\s\S]/],
@@ -354,7 +365,7 @@ class Javascript {
354
365
  if (queue.isClass) scope.isprop = !last || last.isprop || last.type === STAMP && last.text === ';';
355
366
  }
356
367
  else if (scope.type === STAMP) {
357
- scope.isprop = scope.text === "*" && isProperty();
368
+ scope.isprop = scope.text === "*" && (!queue.lastUncomment || /^[,;]$/.test(queue.lastUncomment.text) || queue.isClass && isShortMethodEnd(queue.lastUncomment));
358
369
  }
359
370
  else if (scope.type === PROPERTY) {
360
371
  scope.isprop = true;
@@ -37,9 +37,24 @@ function main(paytypes, price, subject = '网站扫码支付') {
37
37
  drag.on(page.firstChild, page);
38
38
  resize.on(page);
39
39
  var frame = page.querySelector("iframe");
40
+ var tradeid;
40
41
  bind("message")(frame, function (e) {
41
- var id = e.data;
42
- cast(page, 'payment', id);
42
+ if (tradeid === e.data && !queryres) cast(page, 'payment', tradeid), queryres = tradeid;
43
+ else tradeid = e.data, queryres = null;
43
44
  });
45
+ var queryurl, queryres;
46
+ data.bindInstance("paytype", function ({ value }) {
47
+ var type = paytypes[value - 1];
48
+ queryurl = type && type.query;
49
+ });
50
+ var query = lazy(async function () {
51
+ if (!tradeid || queryres) return;
52
+ if (isFunction(queryurl)) var res = await queryurl(tradeid);
53
+ else if (isString(queryurl)) var res = await cross('get', queryurl + encode62.timeencode(tradeid)), res = JSAM.parse(res.response || res.responseText);
54
+ if (queryres) return;
55
+ if (res) queryres = res, cast(page, 'payment', res._id);
56
+ }, -200);
57
+ on('load')(frame, query);
58
+ on('remove')(frame, query);
44
59
  return page;
45
60
  }
@@ -44,14 +44,15 @@ return cross_.bind(function (callback, onerror) {
44
44
  data = Buffer.from(data);
45
45
  this.headers["Content-Length"] = data.length;
46
46
  }
47
- var req = http.request({
47
+ var options = {
48
48
  method: this.method,
49
49
  hostname,
50
50
  port,
51
51
  path,
52
52
  auth,
53
53
  headers: this.headers,
54
- }, function (res) {
54
+ };
55
+ var req = this.http.request(options, function (res) {
55
56
  var data = [];
56
57
  xhr.status = res.statusCode;
57
58
  xhr.responseHeaders = res.headers;
@@ -72,6 +73,7 @@ return cross_.bind(function (callback, onerror) {
72
73
  this.readyState = 2;
73
74
  });
74
75
  this.readyState = 1;
76
+ req.setTimeout(3000);
75
77
  if (data) req.end(data);
76
78
  else req.end();
77
79
  },
@@ -84,7 +86,7 @@ return cross_.bind(function (callback, onerror) {
84
86
  responseObject = null;
85
87
  error = null;
86
88
  var http;
87
- if (/^https?\:/i.test(url)) {
89
+ if (/^http\:/i.test(url)) {
88
90
  http = require("http");
89
91
  }
90
92
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "efront",
3
- "version": "3.21.6",
3
+ "version": "3.22.2",
4
4
  "description": "一个开发工具,开放源代码,自带组件库和编译环境,可以用来开发web组件,web应用或nodejs模块,或做为已有代码的加密工具,也可以做为静态页面服务器或跨域中转服务器使用",
5
5
  "main": "public/efront.js",
6
6
  "directories": {