From a73691914aa147c370b9c3edf9c0de434764dbf5 Mon Sep 17 00:00:00 2001 From: lf <1534621107@qq.com> Date: Thu, 11 Jul 2024 10:04:48 +0800 Subject: [PATCH] first commit --- .gitignore | 2 + .mini-ide/compileMode.json | 10 +++ .mini-ide/project-ide.json | 3 + api/index.js | 24 ++++++ app.acss | 5 ++ app.js | 11 +++ app.json | 11 +++ mini.project.json | 3 + pages/index/index.acss | 129 ++++++++++++++++++++++++++++ pages/index/index.axml | 38 +++++++++ pages/index/index.js | 79 +++++++++++++++++ pages/index/index.json | 1 + utils/base64.js | 171 +++++++++++++++++++++++++++++++++++++ 13 files changed, 487 insertions(+) create mode 100644 .gitignore create mode 100644 .mini-ide/compileMode.json create mode 100644 .mini-ide/project-ide.json create mode 100644 api/index.js create mode 100644 app.acss create mode 100644 app.js create mode 100644 app.json create mode 100644 mini.project.json create mode 100644 pages/index/index.acss create mode 100644 pages/index/index.axml create mode 100644 pages/index/index.js create mode 100644 pages/index/index.json create mode 100644 utils/base64.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9b8c06c --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.tea +node_modules diff --git a/.mini-ide/compileMode.json b/.mini-ide/compileMode.json new file mode 100644 index 0000000..c310a20 --- /dev/null +++ b/.mini-ide/compileMode.json @@ -0,0 +1,10 @@ +{ + "modes": [ + { + "title": "pages/index/index", + "page": "pages/index/index", + "pageQuery": "order_number=aWhvT3RTUFhERUJ6M3FwK09uVkxUbjdWWTQwT1lxTjArWmJuRExsRjJJQT0=", + "query": "" + } + ] +} \ No newline at end of file diff --git a/.mini-ide/project-ide.json b/.mini-ide/project-ide.json new file mode 100644 index 0000000..4d5b574 --- /dev/null +++ b/.mini-ide/project-ide.json @@ -0,0 +1,3 @@ +{ + "ignoreHttpDomainCheck": true +} \ No newline at end of file diff --git a/api/index.js b/api/index.js new file mode 100644 index 0000000..7e9d8b0 --- /dev/null +++ b/api/index.js @@ -0,0 +1,24 @@ +const baseUrl = "http://test.marketapi.1688sup.com"; //测试 +// const baseUrl="http://pre.marketapi.1688sup.com" //镜像 +// const baseUrl="https://marketapi.1688sup.com" //正式 + +//api全局封装 +const request = async (type, url, params) => { + return my.request({ + url: baseUrl + url, + method: type, + data: params, + }).then((res) => { + return res.data; + }).catch({}) +} + +//获取订单详情 +export const getInfo = (parmas) => { + return request('post', '/alipay/cash/orderInfo', parmas); +} + +//领取红包 +export const receiveRed = (parmas) => { + return request('post', '/alipay/cash/receive', parmas); +} diff --git a/app.acss b/app.acss new file mode 100644 index 0000000..b2f5dce --- /dev/null +++ b/app.acss @@ -0,0 +1,5 @@ + +page { + height: 100%; + width: 100%; +} diff --git a/app.js b/app.js new file mode 100644 index 0000000..a8bb15e --- /dev/null +++ b/app.js @@ -0,0 +1,11 @@ +App({ + onLaunch(options) { + // 第一次打开 + // options.query == {number:1} + console.info('App onLaunch'); + }, + onShow(options) { + // 从后台被 scheme 重新打开 + // options.query == {number:1} + }, +}); diff --git a/app.json b/app.json new file mode 100644 index 0000000..8b28f92 --- /dev/null +++ b/app.json @@ -0,0 +1,11 @@ +{ + "pages": [ + "pages/index/index" + ], + "window": { + "defaultTitle": "现金红包" + }, + "behavior": { + "requestReferrerStrategy": "page" + } +} diff --git a/mini.project.json b/mini.project.json new file mode 100644 index 0000000..6a67879 --- /dev/null +++ b/mini.project.json @@ -0,0 +1,3 @@ +{ + "enableAppxNg": true +} \ No newline at end of file diff --git a/pages/index/index.acss b/pages/index/index.acss new file mode 100644 index 0000000..229ba5d --- /dev/null +++ b/pages/index/index.acss @@ -0,0 +1,129 @@ +.redPackets { + height: 100vh; + width: 100%; + padding: 50rpx; + box-sizing: border-box; + display: flex; + justify-content: center; + align-items: center; + background: url('https://lsxdemall.oss-cn-beijing.aliyuncs.com/MarketingSystem/img/redPacktes/redPackets_bg.png') no-repeat; + background-size: 100% 100%; +} + +.redPackets-box { + height: 740rpx; + width: 532rpx; + background-image: url('https://lsxdemall.oss-cn-beijing.aliyuncs.com/MarketingSystem/img/redPacktes/notOpen.png'); + background-repeat: no-repeat; + background-size: contain; + padding-top: 190rpx; + padding-bottom: 50rpx; + margin-top: -120rpx; + display: flex; + flex-direction: column; + align-items: center; + justify-content: space-between; + box-sizing: border-box; + /* border: 1rpx solid; */ +} + +.res { + font-size: 40rpx !important; +} + +.top-box { + display: flex; + flex-direction: column; + align-items: center; +} + +.title { + font-size: 46rpx; + color: rgb(254, 244, 217); + display: inline-block; + font-weight: bold; + margin-bottom: 24rpx; + text-shadow: 0.1rpx 0.1rpx rgb(255, 249, 232); +} + +.type { + display: inline-block; + padding: 10rpx 46rpx; + border: 1rpx solid rgb(254, 244, 217); + border-radius: 50rpx; + font-size: 22rpx; + color: rgb(254, 244, 217); +} + +.time { + display: inline-block; + font-size: 22rpx; + color: rgb(249, 181, 134); +} + +/* */ +.open-redPackets-box { + height: 800rpx; + width: 580rpx; + background-image: url('https://lsxdemall.oss-cn-beijing.aliyuncs.com/MarketingSystem/img/redPacktes/open.png'); + background-repeat: no-repeat; + background-size: contain; + padding-top: 175rpx; + padding-bottom: 110rpx; + margin-top: -75rpx; + margin-left: -46rpx; + display: flex; + flex-direction: column; + align-items: center; + justify-content: space-between; + box-sizing: border-box; + /* border: 1rpx solid; */ +} + +.open-top-box { + display: flex; + flex-direction: column; + align-items: center; + margin-left: 35rpx; +} + +.open-title { + font-size: 90rpx; + color: rgb(245, 72, 54); + display: inline-block; + font-weight: bold; + text-shadow: 0.1rpx 0.1rpx rgb(255, 249, 232); +} + +.open-tag { + font-size: 30rpx; +} + +.open-type { + display: inline-block; + font-size: 20rpx; + color: rgb(245, 72, 54); + width: 400rpx; + text-align: center; + margin-top: 16rpx; + line-height: 28rpx; +} + +.open-time { + display: inline-block; + font-size: 22rpx; + color: rgb(249, 181, 134); +} + +.open-notis { + color: rgb(254, 244, 217); + font-size: 22rpx; + margin-left: 35rpx; + margin-bottom: 70rpx; +} + +.re { + font-size: 26rpx; + text-align: center; + margin-bottom: 20rpx; +} \ No newline at end of file diff --git a/pages/index/index.axml b/pages/index/index.axml new file mode 100644 index 0000000..546fddc --- /dev/null +++ b/pages/index/index.axml @@ -0,0 +1,38 @@ + + + + {{info.batch_goods_name}} + + {{info.cash_amount_type_text}} + + + 红包有效期截止 {{info.end_time}} + + + + + + + {{info.receive_price}} + + + {{info.wishing}} + + + + + 领取成功 + + 请前往支付宝【我的】-【账单】中查看 + + + + + 已被领取 + + + + + + + \ No newline at end of file diff --git a/pages/index/index.js b/pages/index/index.js new file mode 100644 index 0000000..154d05f --- /dev/null +++ b/pages/index/index.js @@ -0,0 +1,79 @@ +import { getInfo, receiveRed } from "../../api"; +import { Base64 } from '../../utils/base64'; +Page({ + data: { + isOpen: false, + order_number: '', + info: { + batch_goods_name: "现金红包", + cash_amount_type_text: "固额红包", + end_time: "2023-06-30 23:59:59", + receive_price: 0.01, + receive_status: 0, + wishing: "恭喜发财", + }, + auth_code: '', + }, + + + onLoad({ order_number }) { + /* 直接通过小程序打开,判断是否有 order_number */ + if (order_number) { + this.setData({ order_number: Base64.decode(order_number) }) + } else { + const { data } = my.getStorageSync({ key: "order_number" }) + data && this.setData({ order_number: data }) + } + + /* 获取详情 */ + if (!this.data.order_number) return + my.showLoading() + getInfo({ order_number: this.data.order_number }) + .then(({ code, data, message }) => { + my.hideLoading() + if (code == 200) { + my.setStorageSync({ key: 'order_number', data: this.data.order_number, }) + this.setData({ info: data }) + if ([1, 2].includes(data.receive_status)) { + this.setData({ isOpen: true }) + } + if (data.receive_status === 3) { + my.alert({ title: '温馨提示', content: data.receive_status_text }) + } + } else { + my.alert({ title: '温馨提示', content: message }) + } + }) + }, + + /* 授权 */ + getAuthCode() { + my.getAuthCode({ + scopes: 'auth_user', + success: ({ authCode }) => { + this.setData({ auth_code: authCode }) + this.receive() + }, + }); + }, + + /* 领取红包 */ + receive() { + /* 订单号存在以及订单未领取才可操作 */ + if (this.data.order_number && this.data.info.receive_status === 0) { + my.showLoading() + receiveRed({ order_number: this.data.order_number, auth_code: this.data.auth_code }) + .then(({ code, message }) => { + if (code === 200) { + const info = this.data.info + info.receive_status = 5 + this.setData({ info, isOpen: true }) + } + my.hideLoading() + my.alert({ title: '温馨提示', content: message }) + }) + } else { + this.setData({ isOpen: true }) + } + } +}); \ No newline at end of file diff --git a/pages/index/index.json b/pages/index/index.json new file mode 100644 index 0000000..9e26dfe --- /dev/null +++ b/pages/index/index.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/utils/base64.js b/utils/base64.js new file mode 100644 index 0000000..bafafa3 --- /dev/null +++ b/utils/base64.js @@ -0,0 +1,171 @@ +/** +* UTF16和UTF8转换对照表 +* U+00000000 – U+0000007F 0xxxxxxx +* U+00000080 – U+000007FF 110xxxxx 10xxxxxx +* U+00000800 – U+0000FFFF 1110xxxx 10xxxxxx 10xxxxxx +* U+00010000 – U+001FFFFF 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx +* U+00200000 – U+03FFFFFF 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx +* U+04000000 – U+7FFFFFFF 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx +*/ +//外部js引用时这样写:import {Base64} from '/xxx/base64';//路径需要根据实际路径去写 +export let Base64 = { + // 转码表 + tables : [ + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', + 'I', 'J', 'K', 'L', 'M', 'N', 'O' ,'P', + 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', + 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', + 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', + 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', + 'w', 'x', 'y', 'z', '0', '1', '2', '3', + '4', '5', '6', '7', '8', '9', '+', '/' + ], + UTF16ToUTF8 : function (str) { + let results = [], len = str.length; + for (let i = 0; i < len; i++) { + let code = str.charCodeAt(i); + if (code > 0x0000 && code <= 0x007F) { + /* 一字节,不考虑0x0000,因为是空字节 + U+00000000 – U+0000007F 0xxxxxxx + */ + results.push(str.charAt(i)); + } else if (code >= 0x0080 && code <= 0x07FF) { + /* 二字节 + U+00000080 – U+000007FF 110xxxxx 10xxxxxx + 110xxxxx + */ + let byte1 = 0xC0 | ((code >> 6) & 0x1F); + // 10xxxxxx + let byte2 = 0x80 | (code & 0x3F); + results.push( + String.fromCharCode(byte1), + String.fromCharCode(byte2) + ); + } else if (code >= 0x0800 && code <= 0xFFFF) { + /* 三字节 + U+00000800 – U+0000FFFF 1110xxxx 10xxxxxx 10xxxxxx + 1110xxxx + */ + let byte1 = 0xE0 | ((code >> 12) & 0x0F); + // 10xxxxxx + let byte2 = 0x80 | ((code >> 6) & 0x3F); + // 10xxxxxx + let byte3 = 0x80 | (code & 0x3F); + results.push( + String.fromCharCode(byte1), + String.fromCharCode(byte2), + String.fromCharCode(byte3) + ); + } else if (code >= 0x00010000 && code <= 0x001FFFFF) { + // 四字节 + // U+00010000 – U+001FFFFF 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx + } else if (code >= 0x00200000 && code <= 0x03FFFFFF) { + // 五字节 + // U+00200000 – U+03FFFFFF 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx + } else /** if (code >= 0x04000000 && code <= 0x7FFFFFFF)*/ { + // 六字节 + // U+04000000 – U+7FFFFFFF 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx + } + } + return results.join(''); + }, + UTF8ToUTF16 : function (str) { + let results = [], len = str.length; + let i = 0; + for (let i = 0; i < len; i++) { + let code = str.charCodeAt(i); + // 第一字节判断 + if (((code >> 7) & 0xFF) == 0x0) { + // 一字节 + // 0xxxxxxx + results.push(str.charAt(i)); + } else if (((code >> 5) & 0xFF) == 0x6) { + // 二字节 + // 110xxxxx 10xxxxxx + let code2 = str.charCodeAt(++i); + let byte1 = (code & 0x1F) << 6; + let byte2 = code2 & 0x3F; + let utf16 = byte1 | byte2; + results.push(Sting.fromCharCode(utf16)); + } else if (((code >> 4) & 0xFF) == 0xE) { + // 三字节 + // 1110xxxx 10xxxxxx 10xxxxxx + let code2 = str.charCodeAt(++i); + let code3 = str.charCodeAt(++i); + let byte1 = (code << 4) | ((code2 >> 2) & 0x0F); + let byte2 = ((code2 & 0x03) << 6) | (code3 & 0x3F); + let utf16 = ((byte1 & 0x00FF) << 8) | byte2 + results.push(String.fromCharCode(utf16)); + } else if (((code >> 3) & 0xFF) == 0x1E) { + // 四字节 + // 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx + } else if (((code >> 2) & 0xFF) == 0x3E) { + // 五字节 + // 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx + } else /** if (((code >> 1) & 0xFF) == 0x7E)*/ { + // 六字节 + // 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx + } + } + return results.join(''); + }, + encode : function (str) { + if (!str) { + return ''; + } + let utf8 = this.UTF16ToUTF8(str); // 转成UTF-8 + let i = 0; // 遍历索引 + let len = utf8.length; + let results = []; + while (i < len) { + let c1 = utf8.charCodeAt(i++) & 0xFF; + results.push(this.tables[c1 >> 2]); + // 补2个= + if (i == len) { + results.push(this.tables[(c1 & 0x3) << 4]); + results.push('=='); + break; + } + let c2 = utf8.charCodeAt(i++); + // 补1个= + if (i == len) { + results.push(this.tables[((c1 & 0x3) << 4) | ((c2 >> 4) & 0x0F)]); + results.push(this.tables[(c2 & 0x0F) << 2]); + results.push('='); + break; + } + let c3 = utf8.charCodeAt(i++); + results.push(this.tables[((c1 & 0x3) << 4) | ((c2 >> 4) & 0x0F)]); + results.push(this.tables[((c2 & 0x0F) << 2) | ((c3 & 0xC0) >> 6)]); + results.push(this.tables[c3 & 0x3F]); + } + return results.join(''); + }, + decode : function (str) { + //判断是否为空 + if (!str) { + return ''; + } + let len = str.length; + let i = 0; + let results = []; + //循环解出字符数组 + while (i < len) { + let code1 = this.tables.indexOf(str.charAt(i++)); + let code2 = this.tables.indexOf(str.charAt(i++)); + let code3 = this.tables.indexOf(str.charAt(i++)); + let code4 = this.tables.indexOf(str.charAt(i++)); + let c1 = (code1 << 2) | (code2 >> 4); + results.push(String.fromCharCode(c1)); + if (code3 != -1) { + let c2 = ((code2 & 0xF) << 4) | (code3 >> 2); + results.push(String.fromCharCode(c2)); + } + if (code4 != -1) { + let c3 = ((code3 & 0x3) << 6) | code4; + results.push(String.fromCharCode(c3)); + } + } + return this.UTF8ToUTF16(results.join('')); + } +}; \ No newline at end of file