Skip to content

Commit 639b9ab

Browse files
committed
增加app微信支付功能
1 parent 1794352 commit 639b9ab

File tree

11 files changed

+268
-21
lines changed

11 files changed

+268
-21
lines changed

App.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
globalData: {
66
h5Domain: 'https://flpt.jxsupplier.com',
77
goLogin: false,
8-
subDomain: 'jdjf0115', // jdjf0115
9-
merchantId: '42151', // 42151
8+
subDomain: 'tz', // jdjf0115
9+
merchantId: '951', // 42151
1010
version: '0.0.2',
1111
sysconfigkeys: 'mallName,shopMod,share_profile,recharge_amount_min,open_growth,shopping_cart_vop_open',
1212
wxpayOpenAppId: 'wx9b04553fd8c7b9c3' // 微信开放平台的移动端应用appID

pages/asset/recharge.vue

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,31 @@
116116
location.href = res.data.mweb_url
117117
}
118118
// #endif
119+
// #ifdef APP-PLUS
120+
// https://www.yuque.com/apifm/nu0f75/uvauoz
121+
const res = await this.$wxapi.wxpayApp({
122+
token: this.token,
123+
appid: getApp().globalData.wxpayOpenAppId,
124+
money: this.amount,
125+
remark: '在线充值',
126+
payName: '在线充值'
127+
})
128+
uni.requestPayment({
129+
provider: 'wxpay', // alipay wxpay baidu appleiap
130+
orderInfo: res.data, // https://uniapp.dcloud.io/api/plugins/payment?id=orderinfo
131+
success: res => {
132+
uni.navigateTo({
133+
url: "/pages/asset/balance"
134+
})
135+
},
136+
fail: err => {
137+
uni.showToast({
138+
title: '支付失败',
139+
icon: 'none'
140+
})
141+
}
142+
})
143+
// #endif
119144
}
120145
}
121146
}

pages/login/login.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@
6464
async submit() {
6565
// https://www.yuque.com/apifm/nu0f75/xrg5e0
6666
const res = await this.$wxapi.login_mobile(this.form.mobile, this.form.pwd, 'tianshitongzhuang', 'h5')
67-
console.log(res);
6867
if(res.code != 0) {
6968
uni.showToast({
7069
title: res.msg,

pages/order/index.vue

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@
272272
}
273273
// #endif
274274
// #ifdef APP-PLUS
275-
// TODO SDK 地址
275+
// https://www.yuque.com/apifm/nu0f75/uvauoz
276276
const res = await this.$wxapi.wxpayApp({
277277
token: this.token,
278278
appid: getApp().globalData.wxpayOpenAppId,
@@ -281,17 +281,17 @@
281281
payName: '支付订单 :' + orderInfo.id,
282282
nextAction: `{type: 0, id: ${orderInfo.id}}`
283283
})
284-
console.log(res);
285284
uni.requestPayment({
286285
provider: 'wxpay', // alipay wxpay baidu appleiap
287-
orderInfo: { // https://uniapp.dcloud.io/api/plugins/payment?id=orderinfo
288-
289-
},
286+
orderInfo: res.data, // https://uniapp.dcloud.io/api/plugins/payment?id=orderinfo
290287
success: res => {
291-
console.log(res);
288+
this.change(1)
292289
},
293290
fail: err => {
294-
console.log(err);
291+
uni.showToast({
292+
title: '支付失败',
293+
icon: 'none'
294+
})
295295
}
296296
})
297297
// #endif

pages/pay/maidan.vue

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,32 @@
184184
money: this.form.amount
185185
})
186186
// #endif
187+
// #ifdef APP-PLUS
188+
// https://www.yuque.com/apifm/nu0f75/uvauoz
189+
const res = await this.$wxapi.wxpayApp({
190+
token: this.token,
191+
appid: getApp().globalData.wxpayOpenAppId,
192+
money: this.form.amount,
193+
remark: '优惠买单',
194+
payName: '优惠买单',
195+
nextAction: `{type: 4, shopId: '', money: ${this.form.amount}}`
196+
})
197+
uni.requestPayment({
198+
provider: 'wxpay', // alipay wxpay baidu appleiap
199+
orderInfo: res.data, // https://uniapp.dcloud.io/api/plugins/payment?id=orderinfo
200+
success: res => {
201+
uni.navigateTo({
202+
url: "/pages/asset/cashlog"
203+
})
204+
},
205+
fail: err => {
206+
uni.showToast({
207+
title: '支付失败',
208+
icon: 'none'
209+
})
210+
}
211+
})
212+
// #endif
187213
}
188214
},
189215
}

pages/pay/order.vue

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,32 @@
400400
location.href = res.data.mweb_url
401401
}
402402
// #endif
403+
// #ifdef APP-PLUS
404+
// https://www.yuque.com/apifm/nu0f75/uvauoz
405+
const res = await this.$wxapi.wxpayApp({
406+
token: this.token,
407+
appid: getApp().globalData.wxpayOpenAppId,
408+
money: needPay,
409+
remark: '支付订单 :' + orderInfo.id,
410+
payName: '支付订单 :' + orderInfo.id,
411+
nextAction: `{type: 0, id: ${orderInfo.id}}`
412+
})
413+
uni.requestPayment({
414+
provider: 'wxpay', // alipay wxpay baidu appleiap
415+
orderInfo: res.data, // https://uniapp.dcloud.io/api/plugins/payment?id=orderinfo
416+
success: res => {
417+
uni.redirectTo({
418+
url: "../order/index?status=0"
419+
})
420+
},
421+
fail: err => {
422+
uni.showToast({
423+
title: '支付失败',
424+
icon: 'none'
425+
})
426+
}
427+
})
428+
// #endif
403429
}
404430
},
405431
}

uni_modules/uview-ui/components/u-search/props.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ export default {
8080
type: String,
8181
default: uni.$u.props.search.searchIcon
8282
},
83+
searchIconSize: {
84+
type: [Number, String],
85+
default: uni.$u.props.search.searchIconSize
86+
},
8387
// 组件与其他上下左右元素之间的距离,带单位的字符串形式,如"30px"、"30px 20px"等写法
8488
margin: {
8589
type: String,

uni_modules/uview-ui/components/u-search/u-search.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<view class="u-search__content__icon">
2323
<u-icon
2424
@tap="clickIcon"
25-
:size="22"
25+
:size="searchIconSize"
2626
:name="searchIcon"
2727
:color="searchIconColor ? searchIconColor : color"
2828
></u-icon>
@@ -91,6 +91,7 @@
9191
* @property {Boolean} disabled 是否启用输入框(默认 false )
9292
* @property {String} borderColor 边框颜色,配置了颜色,才会有边框 (默认 'transparent' )
9393
* @property {String} searchIconColor 搜索图标的颜色,默认同输入框字体颜色 (默认 '#909399' )
94+
* @property {Number | String} searchIconSize 搜索图标的字体,默认26
9495
* @property {String} color 输入框字体颜色(默认 '#606266' )
9596
* @property {String} placeholderColor placeholder的颜色(默认 '#909399' )
9697
* @property {String} searchIcon 输入框左边的图标,可以为uView图标名称或图片路径 (默认 'search' )

uni_modules/uview-ui/libs/config/props/search.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export default {
2323
disabled: false,
2424
borderColor: 'transparent',
2525
searchIconColor: '#909399',
26+
searchIconSize: 22,
2627
color: '#606266',
2728
placeholderColor: '#909399',
2829
searchIcon: 'search',
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
let _boundaryCheckingState = true; // 是否进行越界检查的全局开关
2+
3+
/**
4+
* 把错误的数据转正
5+
* @private
6+
* @example strip(0.09999999999999998)=0.1
7+
*/
8+
function strip(num, precision = 15) {
9+
return +parseFloat(Number(num).toPrecision(precision));
10+
}
11+
12+
/**
13+
* Return digits length of a number
14+
* @private
15+
* @param {*number} num Input number
16+
*/
17+
function digitLength(num) {
18+
// Get digit length of e
19+
const eSplit = num.toString().split(/[eE]/);
20+
const len = (eSplit[0].split('.')[1] || '').length - +(eSplit[1] || 0);
21+
return len > 0 ? len : 0;
22+
}
23+
24+
/**
25+
* 把小数转成整数,如果是小数则放大成整数
26+
* @private
27+
* @param {*number} num 输入数
28+
*/
29+
function float2Fixed(num) {
30+
if (num.toString().indexOf('e') === -1) {
31+
return Number(num.toString().replace('.', ''));
32+
}
33+
const dLen = digitLength(num);
34+
return dLen > 0 ? strip(Number(num) * Math.pow(10, dLen)) : Number(num);
35+
}
36+
37+
/**
38+
* 检测数字是否越界,如果越界给出提示
39+
* @private
40+
* @param {*number} num 输入数
41+
*/
42+
function checkBoundary(num) {
43+
if (_boundaryCheckingState) {
44+
if (num > Number.MAX_SAFE_INTEGER || num < Number.MIN_SAFE_INTEGER) {
45+
console.warn(`${num} 超出了精度限制,结果可能不正确`);
46+
}
47+
}
48+
}
49+
50+
/**
51+
* 把递归操作扁平迭代化
52+
* @param {number[]} arr 要操作的数字数组
53+
* @param {function} operation 迭代操作
54+
* @private
55+
*/
56+
function iteratorOperation(arr, operation) {
57+
const [num1, num2, ...others] = arr;
58+
let res = operation(num1, num2);
59+
60+
others.forEach((num) => {
61+
res = operation(res, num);
62+
});
63+
64+
return res;
65+
}
66+
67+
/**
68+
* 高精度乘法
69+
* @export
70+
*/
71+
export function times(...nums) {
72+
if (nums.length > 2) {
73+
return iteratorOperation(nums, times);
74+
}
75+
76+
const [num1, num2] = nums;
77+
const num1Changed = float2Fixed(num1);
78+
const num2Changed = float2Fixed(num2);
79+
const baseNum = digitLength(num1) + digitLength(num2);
80+
const leftValue = num1Changed * num2Changed;
81+
82+
checkBoundary(leftValue);
83+
84+
return leftValue / Math.pow(10, baseNum);
85+
}
86+
87+
/**
88+
* 高精度加法
89+
* @export
90+
*/
91+
export function plus(...nums) {
92+
if (nums.length > 2) {
93+
return iteratorOperation(nums, plus);
94+
}
95+
96+
const [num1, num2] = nums;
97+
// 取最大的小数位
98+
const baseNum = Math.pow(10, Math.max(digitLength(num1), digitLength(num2)));
99+
// 把小数都转为整数然后再计算
100+
return (times(num1, baseNum) + times(num2, baseNum)) / baseNum;
101+
}
102+
103+
/**
104+
* 高精度减法
105+
* @export
106+
*/
107+
export function minus(...nums) {
108+
if (nums.length > 2) {
109+
return iteratorOperation(nums, minus);
110+
}
111+
112+
const [num1, num2] = nums;
113+
const baseNum = Math.pow(10, Math.max(digitLength(num1), digitLength(num2)));
114+
return (times(num1, baseNum) - times(num2, baseNum)) / baseNum;
115+
}
116+
117+
/**
118+
* 高精度除法
119+
* @export
120+
*/
121+
export function divide(...nums) {
122+
if (nums.length > 2) {
123+
return iteratorOperation(nums, divide);
124+
}
125+
126+
const [num1, num2] = nums;
127+
const num1Changed = float2Fixed(num1);
128+
const num2Changed = float2Fixed(num2);
129+
checkBoundary(num1Changed);
130+
checkBoundary(num2Changed);
131+
// 重要,这里必须用strip进行修正
132+
return times(num1Changed / num2Changed, strip(Math.pow(10, digitLength(num2) - digitLength(num1))));
133+
}
134+
135+
/**
136+
* 四舍五入
137+
* @export
138+
*/
139+
export function round(num, ratio) {
140+
const base = Math.pow(10, ratio);
141+
let result = divide(Math.round(Math.abs(times(num, base))), base);
142+
if (num < 0 && result !== 0) {
143+
result = times(result, -1);
144+
}
145+
// 位数不足则补0
146+
return result;
147+
}
148+
149+
/**
150+
* 是否进行边界检查,默认开启
151+
* @param flag 标记开关,true 为开启,false 为关闭,默认为 true
152+
* @export
153+
*/
154+
export function enableBoundaryChecking(flag = true) {
155+
_boundaryCheckingState = flag;
156+
}
157+
158+
159+
export default {
160+
times,
161+
plus,
162+
minus,
163+
divide,
164+
round,
165+
enableBoundaryChecking,
166+
};
167+

uni_modules/uview-ui/libs/function/index.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import test from './test.js'
2-
2+
import { round } from './digit.js'
33
/**
44
* @description 如果value小于min,取min;如果value大于max,取max
55
* @param {number} min
@@ -294,7 +294,12 @@ if (!String.prototype.padStart) {
294294
}
295295
// 其他都认为符合 RFC 2822 规范
296296
else {
297-
date = new Date(dateTime)
297+
// 处理平台性差异,在Safari/Webkit中,new Date仅支持/作为分割符的字符串时间
298+
date = new Date(
299+
typeof dateTime === 'string'
300+
? dateTime.replace(/-/g, '/')
301+
: dateTime
302+
)
298303
}
299304

300305
const timeSource = {
@@ -506,15 +511,8 @@ function priceFormat(number, decimals = 0, decimalPoint = '.', thousandsSeparato
506511
const sep = (typeof thousandsSeparator === 'undefined') ? ',' : thousandsSeparator
507512
const dec = (typeof decimalPoint === 'undefined') ? '.' : decimalPoint
508513
let s = ''
509-
const toFixedFix = function(n, prec) {
510-
const k = 10 ** (prec)
511-
// 这里写成 乘10 再除10 是因为在部分情况下浮点数运算会有精度损失问题
512-
// 例如 1.15 * 100 的结果为 114.999... , parseInt后就变成了114, 显然与预期不符
513-
// 注意这里 (k * 10)的小括号是必须的,用来保证强制的优先级!
514-
return `${Math.ceil(parseInt(n * (k * 10))) / (k * 10)}`
515-
}
516514

517-
s = (prec ? toFixedFix(n, prec) : `${Math.round(n)}`).split('.')
515+
s = (prec ? round(n, prec) + '' : `${Math.round(n)}`).split('.')
518516
const re = /(-?\d+)(\d{3})/
519517
while (re.test(s[0])) {
520518
s[0] = s[0].replace(re, `$1${sep}$2`)

0 commit comments

Comments
 (0)