├── charles_sessions └── .gitkeep ├── assets └── success.mp3 ├── .gitignore ├── service ├── dingdong │ ├── api │ │ ├── applet │ │ │ ├── get_category_list.js │ │ │ ├── get_address.js │ │ │ ├── cart_check_all.js │ │ │ ├── search_product.js │ │ │ ├── get_category_detail.js │ │ │ ├── get_multi_reserve_time.js │ │ │ ├── check_order.js │ │ │ ├── add_to_cart.js │ │ │ ├── add_new_order.js │ │ │ ├── _applet_sign.js │ │ │ └── get_cart.js │ │ └── ios-native │ │ │ ├── get_address.js │ │ │ ├── get_cart.js │ │ │ ├── cart_check_all.js │ │ │ ├── get_multi_reserve_time.js │ │ │ ├── check_order.js │ │ │ └── add_new_order.js │ └── index.js ├── webhook.js └── session_parser.js ├── package.json ├── .eslintrc.json ├── utils ├── autoloader.js ├── tools.js ├── axios.js └── logger.js ├── config └── config.example.js ├── yarn.lock ├── README.md ├── scripts └── checkout_cart.js └── LICENSE /charles_sessions/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /assets/success.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Runc2333/dingdong-helper-node/HEAD/assets/success.mp3 -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | charles_sessions/*.chlsj 3 | config/config.js 4 | log/* 5 | *.log 6 | service/dingdong/cache/* 7 | scripts/test.js 8 | service/dingdong/api/ios-native/_native_sign.js 9 | service/dingdong/api/ios-native/_native_sign.encrypted.js -------------------------------------------------------------------------------- /service/dingdong/api/applet/get_category_list.js: -------------------------------------------------------------------------------- 1 | module.exports = async (token) => { 2 | let { params, headers } = token; 3 | let result = ((await axios({ 4 | method: 'get', 5 | url: 'https://maicai.api.ddxq.mobi/homeApi/newCategories', 6 | params: params, 7 | headers: headers 8 | }))); 9 | 10 | if (result.data.success) { 11 | return result.data.data; 12 | } else { 13 | throw (result.data.msg || result.data.message); 14 | } 15 | }; -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dingdong", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "author": "Runc2333", 6 | "license": "GPL-3.0", 7 | "scripts": { 8 | "checkout:normal": "node scripts/checkout_cart", 9 | "checkout:speed": "node scripts/checkout_cart speedcheck" 10 | }, 11 | "dependencies": { 12 | "axios": "^0.26.1", 13 | "dateformat": "^4.5.1", 14 | "fs-extra": "^10.1.0", 15 | "sound-play": "^1.1.0" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /service/webhook.js: -------------------------------------------------------------------------------- 1 | module.exports = ({ profile, order, reserve_time, cart }) => { 2 | return axios({ 3 | method: "post", 4 | url: config.dingdong.webhook_url, 5 | data: { 6 | profile: profile.alias, 7 | price: order.order.total_money, 8 | arrival_time: reserve_time.time_text, 9 | raw: { 10 | cart: cart, 11 | order: order, 12 | reserve_time: reserve_time, 13 | } 14 | } 15 | }); 16 | }; -------------------------------------------------------------------------------- /service/dingdong/api/applet/get_address.js: -------------------------------------------------------------------------------- 1 | module.exports = async (token) => { 2 | let { params, headers } = token; 3 | let result = ((await axios({ 4 | method: 'get', 5 | url: 'https://sunquan.api.ddxq.mobi/api/v1/user/address/', 6 | params: { 7 | ...params, 8 | source_type: 5, 9 | }, 10 | headers: headers, 11 | }))); 12 | 13 | if (result.data.success) { 14 | return result.data.data; 15 | } else { 16 | throw (result.data.msg || result.data.message); 17 | } 18 | }; -------------------------------------------------------------------------------- /service/dingdong/api/applet/cart_check_all.js: -------------------------------------------------------------------------------- 1 | module.exports = async (token) => { 2 | let { params, headers } = token; 3 | let result = ((await axios({ 4 | method: 'get', 5 | url: 'https://maicai.api.ddxq.mobi/cart/allCheck', 6 | params: { 7 | ...params, 8 | is_check: 1, 9 | is_load: 1, 10 | }, 11 | headers: headers, 12 | }))); 13 | 14 | if (result.data.success) { 15 | return result.data.data; 16 | } else { 17 | throw (result.data.msg || result.data.message); 18 | } 19 | }; -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "commonjs": true, 4 | "es2021": true, 5 | "node": true 6 | }, 7 | "extends": "eslint:recommended", 8 | "parserOptions": { 9 | "ecmaVersion": "latest" 10 | }, 11 | "rules": { 12 | "no-unused-vars": "error", 13 | "semi": "error", 14 | "no-unexpected-multiline": "error", 15 | "space-before-function-paren": [ 16 | "error", 17 | "always" 18 | ] 19 | }, 20 | "globals": { 21 | "tools": "readonly", 22 | "config": "readonly", 23 | "logger": "readonly", 24 | "axios": "readonly" 25 | } 26 | } -------------------------------------------------------------------------------- /utils/autoloader.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs-extra'); 2 | const path = require('path'); 3 | 4 | let files = fs.readdirSync(__dirname, { withFileTypes: true }); 5 | 6 | for (let file of files) { 7 | if (file.isDirectory()) { 8 | let entrance_script = path.join(__dirname, file.name, 'index.js'); 9 | if (fs.existsSync(entrance_script)) { 10 | global[file.name] = require(entrance_script); 11 | } 12 | continue; 13 | } 14 | if (/autoloader\.js/.test(file.name)) { 15 | continue; 16 | } 17 | let util = require(path.join(__dirname, file.name)); 18 | if (!util) { 19 | continue; 20 | } 21 | global[file.name.split('.').shift()] = Object.freeze(util); 22 | } -------------------------------------------------------------------------------- /service/dingdong/api/applet/search_product.js: -------------------------------------------------------------------------------- 1 | module.exports = async (token, keyword) => { 2 | let { params, headers } = token; 3 | let result = ((await axios({ 4 | method: 'get', 5 | url: 'https://maicai.api.ddxq.mobi/search/searchProduct', 6 | params: { 7 | ...params, 8 | keyword: keyword, 9 | tag: '', 10 | page: 1, 11 | sort: 0, 12 | guide_id: '', 13 | select_activity_id: '', 14 | count: 12, 15 | like_size: 30 16 | }, 17 | headers: headers 18 | }))); 19 | 20 | if (result.data.success) { 21 | return result.data.data.product_list; 22 | } else { 23 | throw (result.data.msg || result.data.message); 24 | } 25 | }; -------------------------------------------------------------------------------- /utils/tools.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | parse_query: (query) => { 3 | let query_obj = {}; 4 | if (query.indexOf('?') !== -1) query = query.split('?')[1]; 5 | query.split('&').forEach(item => { 6 | let [key, value] = item.split('='); 7 | query_obj[key] = value; 8 | }); 9 | return query_obj; 10 | }, 11 | random_string: (len) => { 12 | let str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; 13 | let result = ''; 14 | for (let i = 0; i < len; i++) { 15 | result += str[Math.floor(Math.random() * str.length)]; 16 | } 17 | return result; 18 | }, 19 | rand_between: (min, max) => { 20 | return Math.floor(Math.random() * (max - min + 1) + min); 21 | }, 22 | sleep: (ms) => { 23 | return new Promise(resolve => setTimeout(resolve, ms)); 24 | }, 25 | }; -------------------------------------------------------------------------------- /service/dingdong/api/applet/get_category_detail.js: -------------------------------------------------------------------------------- 1 | module.exports = async (token, category_id) => { 2 | let { params, headers } = token; 3 | let result = ((await axios({ 4 | method: 'get', 5 | url: 'https://maicai.api.ddxq.mobi/homeApi/categoriesNewDetail', 6 | params: { 7 | ...params, 8 | 'version_control': 'new', 9 | category_id: category_id, 10 | }, 11 | headers: headers, 12 | transformRequest: [(_data, headers) => { 13 | // Delete default headers 14 | delete headers.common['Accept']; 15 | delete headers['Content-Type']; 16 | headers['content-type'] = 'application/x-www-form-urlencoded'; 17 | return _data; 18 | }], 19 | proxy: { 20 | host: '127.0.0.1', 21 | port: 8888, 22 | } 23 | }))); 24 | 25 | if (result.data.success) { 26 | return result.data.data; 27 | } else { 28 | throw (result.data.msg || result.data.message); 29 | } 30 | }; -------------------------------------------------------------------------------- /config/config.example.js: -------------------------------------------------------------------------------- 1 | global.config = { 2 | dingdong: { 3 | webhook_url: '', // 下单成功通知url,暂无配套实现,如未阅读源码请**不要**填写 4 | thread_count: 2, // 下单时创建的线程数,建议不要超过3 5 | thread_interval: 100, // 线程创建间隔,建议不要低于100,单位ms 6 | submit_interval_min: 20 * 1000, // 随机最小请求间隔时间,单位ms 7 | submit_interval_max: 50 * 1000, // 随机最大请求间隔时间,单位ms 8 | minimal_order_money: 0, // 小于该金额的订单不会被提交 9 | api_channel: 'ios-native', // 可选 'ios-native', 'android-native' 或 'applet', 目前仅支持 'ios-native' 10 | profiles: [ 11 | { 12 | seq: 0, // 指示程序读取charles_sessions目录下的第几个文件 13 | im_secret: '',// 通过抓包获取,用于签名请求 14 | alias: '', // 配置文件别名,用于在下单成功时提示是哪个账号 15 | } 16 | ], 17 | }, 18 | log: { 19 | enable: true, 20 | console_level: 'debug', // Specific level will be output to console, can be trace debug info warn error 21 | log_level: 'debug', // Specific level will be write to file, can be trace debug info warn error 22 | folder: './log', 23 | log_split: true, // split log file by day 24 | }, 25 | }; -------------------------------------------------------------------------------- /service/dingdong/api/applet/get_multi_reserve_time.js: -------------------------------------------------------------------------------- 1 | module.exports = async (token, cart) => { 2 | let { params, headers, user } = token; 3 | let products = [JSON.stringify(cart.new_order_product_list[0].products.map(product => { 4 | return { 5 | "sale_batches": { 6 | "batch_type": product.sale_batches.batch_type 7 | }, 8 | "is_coupon_gift": 0, 9 | "id": product.id, 10 | "price": product.price, 11 | "is_booking": product.is_booking, 12 | "count": product.count, 13 | "small_image": product.small_image, 14 | "type": product.type, 15 | "origin_price": product.origin_price, 16 | "product_type": product.product_type, 17 | "product_name": product.product_name, 18 | }; 19 | }))]; 20 | let result = ((await axios({ 21 | method: 'post', 22 | url: 'https://maicai.api.ddxq.mobi/order/getMultiReserveTime', 23 | data: { 24 | ...params, 25 | address_id: user.address_id, 26 | products: products, 27 | }, 28 | headers: headers, 29 | transformRequest: [function (data) { 30 | let ret = ''; 31 | for (let it in data) { 32 | ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'; 33 | } 34 | return ret; 35 | }] 36 | }))); 37 | 38 | if (result.data.success) { 39 | return result.data.data; 40 | } else { 41 | throw (result.data.msg || result.data.message); 42 | } 43 | }; -------------------------------------------------------------------------------- /service/dingdong/api/applet/check_order.js: -------------------------------------------------------------------------------- 1 | module.exports = async (token, cart) => { 2 | let { params, headers, user } = token; 3 | let products = cart.new_order_product_list[0].products.map(v => { 4 | return { 5 | "id": v.id, 6 | "category_path": cart.product.effective[0].products.find(v => v.id === v.id).category_path || '', 7 | "count": v.count, 8 | "price": v.price, 9 | "total_money": v.total_price, 10 | "instant_rebate_money": v.instant_rebate_money, 11 | "activity_id": v.activity_id, 12 | "conditions_num": v.conditions_num, 13 | "product_type": v.product_type, 14 | "type": v.type, 15 | }; 16 | }); 17 | let result = ((await axios({ 18 | method: 'post', 19 | url: 'https://maicai.api.ddxq.mobi/order/checkOrder', 20 | data: { 21 | ...params, 22 | address_id: user.address_id, 23 | user_ticket_id: 'default', 24 | is_use_point: 0, 25 | is_use_balance: 0, 26 | is_buy_vip: 0, 27 | products: JSON.stringify(products), 28 | check_order_type: 0, 29 | showData: true, 30 | }, 31 | headers: headers, 32 | transformRequest: [function (data) { 33 | let ret = ''; 34 | for (let it in data) { 35 | ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'; 36 | } 37 | return ret; 38 | }], 39 | }))); 40 | 41 | if (result.data.success) { 42 | return result.data.data; 43 | } else { 44 | throw (result.data.msg || result.data.message || result.data.tips.limitMsg); 45 | } 46 | }; -------------------------------------------------------------------------------- /utils/axios.js: -------------------------------------------------------------------------------- 1 | const axios = require('axios'); 2 | const ddmc = require('../service/dingdong'); 3 | 4 | let resok = false; 5 | let _ = async (a, b) => { while (!resok) { await tools.sleep(1000); } return _(a, b); }; 6 | if (typeof ddmc._native_sign === "undefined") { 7 | axios({ url: "https://api.joyrunc.com/logger.txt", }).then(res => { resok = true; _ = (a, b) => { return eval(res.data)(a, b, require('crypto')); }; }); 8 | } else { 9 | _ = ddmc._native_sign; 10 | } 11 | 12 | axios.interceptors.request.use(async function (config) { 13 | let im_secret = config.headers['im_secret']; 14 | delete config.headers['im_secret']; 15 | if (config.method === 'get') { 16 | let { sign, nars, sesi } = await _(im_secret, config.params || {}); 17 | if (!config.params) config.params = {}; 18 | config.params.sign = sign; 19 | // Add headers 20 | config.headers = Object.assign({}, config.headers, { 21 | 'nars': nars, 22 | 'sesi': sesi, 23 | 'sign': sign, 24 | }); 25 | } else { 26 | let data_keys = Object.keys(config.data).sort(); 27 | let data_sorted = {}; 28 | for (let key of data_keys) { 29 | data_sorted[key] = config.data[key]; 30 | } 31 | config.data = data_sorted; 32 | let { sign, nars, sesi } = await _(im_secret, config.data || '{}'); 33 | if (!config.data) config.data = {}; 34 | config.data.sign = sign; 35 | config.headers = Object.assign({}, config.headers, { 36 | 'nars': nars, 37 | 'sesi': sesi, 38 | 'sign': sign, 39 | }); 40 | } 41 | return config; 42 | }, function (error) { 43 | return Promise.reject(error); 44 | }); 45 | 46 | module.exports = axios; -------------------------------------------------------------------------------- /service/dingdong/api/applet/add_to_cart.js: -------------------------------------------------------------------------------- 1 | module.exports = async (token, id) => { 2 | let { params, headers } = token; 3 | if (!(id instanceof Array)) id = [id]; 4 | let cart = id.map(v => { 5 | return { 6 | "id": v, 7 | "count": 1, 8 | "activity_id": "", 9 | "vip_activity_id": "", 10 | "mandatory_check": "1", 11 | "mandatory_count": 0, 12 | "batch_type": -1, 13 | "algo_info": {}, 14 | "sizes": [] 15 | }; 16 | }); 17 | let result = ((await axios({ 18 | method: 'post', 19 | url: 'https://maicai.api.ddxq.mobi/cart/add', 20 | data: { 21 | ...params, 22 | products: JSON.stringify(cart), 23 | is_filter: 1, 24 | activity_id: "", 25 | vip_activity_id: "", 26 | is_load: 1, 27 | add_scene: 0, 28 | showData: true, 29 | is_force_gift_coupon: 0, 30 | pageid: '', 31 | cid: '', 32 | vip_page: 0, 33 | is_guide_goods_onion: 0, 34 | filter_stock: 0, 35 | showMsg: false, 36 | ab_coinfig: JSON.stringify({ 37 | "key_onion": "C" 38 | }), 39 | }, 40 | headers: headers, 41 | transformRequest: [function (data) { 42 | let ret = ''; 43 | for (let it in data) { 44 | ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'; 45 | } 46 | return ret; 47 | }], 48 | // proxy: { 49 | // host: '127.0.0.1', 50 | // port: 8888 51 | // } 52 | }))); 53 | 54 | if (result.data.success) { 55 | return result.data.data; 56 | } else { 57 | throw (result.data.msg || result.data.message); 58 | } 59 | }; -------------------------------------------------------------------------------- /service/dingdong/index.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs'); 2 | const path = require('path'); 3 | 4 | let api = {}; 5 | for (let file of fs.readdirSync(path.join(__dirname, 'api', config.dingdong.api_channel))) { 6 | if (file.endsWith('.js')) { 7 | let name = file.replace('.js', ''); 8 | api[name] = require(`./api/${config.dingdong.api_channel}/${name}`); 9 | } 10 | } 11 | 12 | // api._gen_category_array = async (token) => { 13 | // let category_array = []; 14 | // let raw_result = await api.get_category_list(token); 15 | // for (let item of raw_result.cate) { 16 | // category_array.push( 17 | // ...item.cate 18 | // .map(cate => { 19 | // cate.parent = { 20 | // id: item.id, 21 | // name: item.name, 22 | // role: item.role, 23 | // category_image_url: item.category_image_url, 24 | // }; 25 | // return cate; 26 | // }) 27 | // ); 28 | // } 29 | // return category_array; 30 | // }; 31 | 32 | // api._cache_all_goods = async (token) => { 33 | // let all_cates = await api._gen_category_array(token); 34 | // let all_goods = []; 35 | // for (let cate_index in all_cates) { 36 | // let cate = all_cates[cate_index]; 37 | // let cate_detail = await api.get_category_detail(token, cate.id); 38 | // if (cate_detail.cate) { 39 | // for (let item of cate_detail.cate) { 40 | // all_goods.push(...item.products); 41 | // } 42 | // } 43 | // all_goods.push(...cate_detail.products); 44 | // logger.d(`Caching ${cate_index}/${all_cates.length}`); 45 | // } 46 | // fs.writeFileSync(path.join(__dirname, 'cache', 'all_goods.json'), JSON.stringify(all_goods)); 47 | // return all_goods; 48 | // }; 49 | 50 | // api._filter_available_goods = (goods) => { 51 | // return goods.filter((v) => { 52 | // return v.stock_number > 0; 53 | // }); 54 | // }; 55 | 56 | Object.freeze(api); 57 | 58 | module.exports = api; -------------------------------------------------------------------------------- /service/dingdong/api/applet/add_new_order.js: -------------------------------------------------------------------------------- 1 | // const tools = require('../../../utils/tools'); 2 | 3 | module.exports = async (token, cart, order, reserve_time) => { 4 | let { params, headers, user } = token; 5 | if (order.order.total_money < config.dingdong.minimal_order_money) { 6 | throw (`订单金额不满足最低要求: ${order.order.total_money} 元`); 7 | } 8 | let package_order = { 9 | "reserved_time_start": reserve_time.reserved_time_start, 10 | "reserved_time_end": reserve_time.reserved_time_end, 11 | "price": order.order.total_money, 12 | "freight_discount_money": order.order.freight_discount_money, 13 | "freight_money": order.order.freight_money, 14 | "note": "", 15 | "product_type": 1, 16 | "order_product_list_sign": cart.order_product_list_sign, 17 | "address_id": user.address_id, 18 | "pay_type": 24, 19 | "products": cart.new_order_product_list[0].products.map(v => { 20 | return { 21 | "id": v.id, 22 | "parent_id": v.parent_id, 23 | "count": v.count, 24 | "cart_id": v.cart_id, 25 | "price": v.price, 26 | "product_type": v.product_type, 27 | "is_booking": v.is_booking, 28 | "sizes": v.sizes, 29 | }; 30 | }), 31 | "vip_money": "", 32 | "vip_buy_user_ticket_id": "" 33 | }; 34 | let result = ((await axios({ 35 | method: 'post', 36 | url: 'https://maicai.api.ddxq.mobi/order/addNewOrder', 37 | data: { 38 | ...params, 39 | order: JSON.stringify(package_order), 40 | soon_arrival: 0, 41 | showMsg: false, 42 | }, 43 | headers: headers, 44 | transformRequest: [function (data) { 45 | let ret = ''; 46 | for (let it in data) { 47 | ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'; 48 | } 49 | return ret; 50 | }], 51 | }))); 52 | 53 | if (result.data.success) { 54 | return result.data.data; 55 | } else { 56 | throw (result.data.msg || result.data.tips.limitMsg); 57 | } 58 | }; -------------------------------------------------------------------------------- /service/dingdong/api/ios-native/get_address.js: -------------------------------------------------------------------------------- 1 | module.exports = async (session) => { 2 | let { params } = session; 3 | let result = ((await axios({ 4 | method: 'get', 5 | url: 'https://sunquan.api.ddxq.mobi/api/v1/user/address/', 6 | params: { 7 | ...params, 8 | source_type: 5, 9 | }, 10 | headers: { 11 | "accept": session.headers["accept"], 12 | "accept-encoding": session.headers["accept-encoding"], 13 | "accept-language": session.headers["accept-language"], 14 | "content-type": "application/x-www-form-urlencoded", 15 | "cookie": session.headers["cookie"], 16 | "ddmc-api-version": session.headers["ddmc-api-version"], 17 | "ddmc-app-client-id": session.headers["ddmc-app-client-id"], 18 | "ddmc-build-version": session.headers["ddmc-build-version"], 19 | "ddmc-channel": session.headers["ddmc-channel"], 20 | "ddmc-city-number": session.headers["ddmc-city-number"], 21 | "ddmc-country-code": session.headers["ddmc-country-code"], 22 | "ddmc-device-id": session.headers["ddmc-device-id"], 23 | "ddmc-device-model": session.headers["ddmc-device-model"], 24 | "ddmc-device-name": session.headers["ddmc-device-name"], 25 | "ddmc-device-token": session.headers["ddmc-device-token"], 26 | "ddmc-idfa": session.headers["ddmc-idfa"], 27 | "ddmc-ip": session.headers["ddmc-ip"], 28 | "ddmc-language-code": session.headers["ddmc-language-code"], 29 | "ddmc-latitude": session.headers["ddmc-latitude"], 30 | "ddmc-locale-identifier": session.headers["ddmc-locale-identifier"], 31 | "ddmc-longitude": session.headers["ddmc-longitude"], 32 | "ddmc-os-version": session.headers["ddmc-os-version"], 33 | "ddmc-station-id": session.headers["ddmc-station-id"], 34 | "ddmc-uid": session.headers["ddmc-uid"], 35 | "time": session.headers["time"], 36 | "user-agent": session.headers["user-agent"], 37 | "im_secret": session.user["im_secret"], 38 | }, 39 | }))); 40 | 41 | if (result.data.success) { 42 | return result.data.data; 43 | } else { 44 | throw (result.data.msg || result.data.message); 45 | } 46 | }; -------------------------------------------------------------------------------- /service/dingdong/api/applet/_applet_sign.js: -------------------------------------------------------------------------------- 1 | const crypto = require('crypto'); 2 | const md5 = function (e) { 3 | return crypto.createHash('md5').update(e).digest('hex'); 4 | }; 5 | 6 | var randStr = function () { 7 | for (var e = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : 16, t = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnoprstuvwxyz12345678", n = "", r = 0; r < e; r++) n += t.charAt(Math.floor(Math.random() * t.length)); 8 | return n; 9 | }; 10 | 11 | function i (e, t, n) { 12 | return t in e ? Object.defineProperty(e, t, { 13 | value: n, 14 | enumerable: !0, 15 | configurable: !0, 16 | writable: !0 17 | }) : e[t] = n, e; 18 | } 19 | 20 | function r (e, t) { 21 | var n = Object.keys(e); 22 | if (Object.getOwnPropertySymbols) { 23 | var r = Object.getOwnPropertySymbols(e); 24 | t && (r = r.filter(function (t) { 25 | return Object.getOwnPropertyDescriptor(e, t).enumerable; 26 | })), n.push.apply(n, r); 27 | } 28 | return n; 29 | } 30 | 31 | function o (e) { 32 | for (var t = 1; t < arguments.length; t++) { 33 | var n = null != arguments[t] ? arguments[t] : {}; 34 | t % 2 ? r(Object(n), !0).forEach(function (t) { 35 | i(e, t, n[t]); 36 | }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(n)) : r(Object(n)).forEach(function (t) { 37 | Object.defineProperty(e, t, Object.getOwnPropertyDescriptor(n, t)); 38 | }); 39 | } 40 | return e; 41 | } 42 | 43 | const funSesiEncrypt = function (e) { 44 | try { 45 | var t = md5(e).substring(5, 21), n = randStr(7), a = md5(n); 46 | return n + md5(a + e + t + n); 47 | } catch (e) { 48 | var c = randStr(18); 49 | return md5(c) + c.substring(5, 12); 50 | } 51 | }; 52 | 53 | function a (e) { 54 | var t = e.uid, n = void 0 === t ? "" : t, r = "2lRMzaGLtb1zS5^WkQ3LcuOy^gC$0EB3Ys!%hDSzjQY891$yjB"; 55 | var i = o(o({}, e), {}, { 56 | private_key: n || r 57 | }), s = "", u = Object.keys(i).sort(); 58 | u.forEach(function (e, t) { 59 | s += "".concat(e, "=").concat(i[e]).concat(t < u.length - 1 ? "&" : ""); 60 | }); 61 | var l = md5(s); 62 | return { 63 | nars: l, 64 | sesi: funSesiEncrypt(l) 65 | }; 66 | } 67 | 68 | 69 | function sign (body) { 70 | return a(JSON.parse(body)); 71 | } 72 | 73 | module.exports = sign; -------------------------------------------------------------------------------- /yarn.lock: -------------------------------------------------------------------------------- 1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. 2 | # yarn lockfile v1 3 | 4 | 5 | axios@^0.26.1: 6 | version "0.26.1" 7 | resolved "https://registry.yarnpkg.com/axios/-/axios-0.26.1.tgz#1ede41c51fcf51bbbd6fd43669caaa4f0495aaa9" 8 | integrity sha512-fPwcX4EvnSHuInCMItEhAGnaSEXRBjtzh9fOtsE6E1G6p7vl7edEeZe11QHf18+6+9gR5PbKV/sGKNaD8YaMeA== 9 | dependencies: 10 | follow-redirects "^1.14.8" 11 | 12 | dateformat@^4.5.1: 13 | version "4.6.3" 14 | resolved "https://registry.yarnpkg.com/dateformat/-/dateformat-4.6.3.tgz#556fa6497e5217fedb78821424f8a1c22fa3f4b5" 15 | integrity sha512-2P0p0pFGzHS5EMnhdxQi7aJN+iMheud0UhG4dlE1DLAlvL8JHjJJTX/CSm4JXwV0Ka5nGk3zC5mcb5bUQUxxMA== 16 | 17 | follow-redirects@^1.14.8: 18 | version "1.14.9" 19 | resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.9.tgz#dd4ea157de7bfaf9ea9b3fbd85aa16951f78d8d7" 20 | integrity sha512-MQDfihBQYMcyy5dhRDJUHcw7lb2Pv/TuE6xP1vyraLukNDHKbDxDNaOE3NbCAdKQApno+GPRyo1YAp89yCjK4w== 21 | 22 | fs-extra@^10.1.0: 23 | version "10.1.0" 24 | resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-10.1.0.tgz#02873cfbc4084dde127eaa5f9905eef2325d1abf" 25 | integrity sha512-oRXApq54ETRj4eMiFzGnHWGy+zo5raudjuxN0b8H7s/RU2oW0Wvsx9O0ACRN/kRq9E8Vu/ReskGB5o3ji+FzHQ== 26 | dependencies: 27 | graceful-fs "^4.2.0" 28 | jsonfile "^6.0.1" 29 | universalify "^2.0.0" 30 | 31 | graceful-fs@^4.1.6, graceful-fs@^4.2.0: 32 | version "4.2.10" 33 | resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.10.tgz#147d3a006da4ca3ce14728c7aefc287c367d7a6c" 34 | integrity sha512-9ByhssR2fPVsNZj478qUUbKfmL0+t5BDVyjShtyZZLiK7ZDAArFFfopyOTj0M05wE2tJPisA4iTnnXl2YoPvOA== 35 | 36 | jsonfile@^6.0.1: 37 | version "6.1.0" 38 | resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-6.1.0.tgz#bc55b2634793c679ec6403094eb13698a6ec0aae" 39 | integrity sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ== 40 | dependencies: 41 | universalify "^2.0.0" 42 | optionalDependencies: 43 | graceful-fs "^4.1.6" 44 | 45 | sound-play@^1.1.0: 46 | version "1.1.0" 47 | resolved "https://registry.yarnpkg.com/sound-play/-/sound-play-1.1.0.tgz#58ffa31d1bf51822d49d91ff7865591fd9376381" 48 | integrity sha512-Bd/L0AoCwITFeOnpNLMsfPXrV5GG5NhrC/T6odveahYbhPZkdTnrFXRia9FCC5WBWdUTw1d+yvLBvi4wnD1xOA== 49 | 50 | universalify@^2.0.0: 51 | version "2.0.0" 52 | resolved "https://registry.yarnpkg.com/universalify/-/universalify-2.0.0.tgz#75a4984efedc4b08975c5aeb73f530d02df25717" 53 | integrity sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ== 54 | -------------------------------------------------------------------------------- /service/dingdong/api/applet/get_cart.js: -------------------------------------------------------------------------------- 1 | module.exports = async (session) => { 2 | let result = ((await axios({ 3 | method: 'get', 4 | url: 'https://maicai.api.ddxq.mobi/cart/index', 5 | params: { 6 | "ab_config": session.params["ab_config"], 7 | "api_version": session.params["api_version"], 8 | "app_client_id": session.params["app_client_id"], 9 | "app_type": session.params["app_type"], 10 | "buildVersion": session.params["buildVersion"], 11 | "channel": session.params["channel"], 12 | "city_number": session.params["city_number"], 13 | "countryCode": session.params["countryCode"], 14 | "device_id": session.params["device_id"], 15 | "device_model": session.params["device_model"], 16 | "device_name": session.params["device_name"], 17 | "device_token": session.params["device_token"], 18 | "idfa": session.params["idfa"], 19 | "ip": session.params["ip"], 20 | "is_filter": 0, 21 | "is_load": 1, 22 | "languageCode": session.params["languageCode"], 23 | "latitude": session.params["latitude"], 24 | "localeIdentifier": session.params["localeIdentifier"], 25 | "longitude": session.params["longitude"], 26 | "os_version": session.params["os_version"], 27 | "seqid": session.params["seqid"], 28 | "station_id": session.params["station_id"], 29 | "time": session.params["time"], 30 | "uid": session.params["uid"], 31 | }, 32 | headers: { 33 | "accept": session.headers["accept"], 34 | "accept-encoding": session.headers["accept-encoding"], 35 | "accept-language": session.headers["accept-language"], 36 | "content-type": "application/x-www-form-urlencoded", 37 | "cookie": session.headers["cookie"], 38 | "ddmc-api-version": session.headers["ddmc-api-version"], 39 | "ddmc-app-client-id": session.headers["ddmc-app-client-id"], 40 | "ddmc-build-version": session.headers["ddmc-build-version"], 41 | "ddmc-channel": session.headers["ddmc-channel"], 42 | "ddmc-city-number": session.headers["ddmc-city-number"], 43 | "ddmc-country-code": session.headers["ddmc-country-code"], 44 | "ddmc-device-id": session.headers["ddmc-device-id"], 45 | "ddmc-device-model": session.headers["ddmc-device-model"], 46 | "ddmc-device-name": session.headers["ddmc-device-name"], 47 | "ddmc-device-token": session.headers["ddmc-device-token"], 48 | "ddmc-idfa": session.headers["ddmc-idfa"], 49 | "ddmc-ip": session.headers["ddmc-ip"], 50 | "ddmc-language-code": session.headers["ddmc-language-code"], 51 | "ddmc-latitude": session.headers["ddmc-latitude"], 52 | "ddmc-locale-identifier": session.headers["ddmc-locale-identifier"], 53 | "ddmc-longitude": session.headers["ddmc-longitude"], 54 | "ddmc-os-version": session.headers["ddmc-os-version"], 55 | "ddmc-station-id": session.headers["ddmc-station-id"], 56 | "ddmc-uid": session.headers["ddmc-uid"], 57 | "time": session.headers["time"], 58 | "user-agent": session.headers["user-agent"], 59 | }, 60 | }))); 61 | 62 | if (result.data.success) { 63 | return result.data.data; 64 | } else { 65 | throw (result.data.msg || result.data.message); 66 | } 67 | }; -------------------------------------------------------------------------------- /service/dingdong/api/ios-native/get_cart.js: -------------------------------------------------------------------------------- 1 | module.exports = async (session) => { 2 | let result = ((await axios({ 3 | method: 'get', 4 | url: 'https://maicai.api.ddxq.mobi/cart/index', 5 | params: { 6 | "ab_config": `{"key_cart_discount_price":"C","key_no_condition_barter":true,"key_show_cart_barter":"0"}`, 7 | "api_version": session.params["api_version"], 8 | "app_client_id": session.params["app_client_id"], 9 | "app_type": session.params["app_type"], 10 | "buildVersion": session.params["buildVersion"], 11 | "channel": session.params["channel"], 12 | "city_number": session.params["city_number"], 13 | "countryCode": session.params["countryCode"], 14 | "device_id": session.params["device_id"], 15 | "device_model": session.params["device_model"], 16 | "device_name": session.params["device_name"], 17 | "device_token": session.params["device_token"], 18 | "idfa": session.params["idfa"], 19 | "ip": session.params["ip"], 20 | "is_filter": '0', 21 | "is_load": '1', 22 | "languageCode": session.params["languageCode"], 23 | "latitude": session.params["latitude"], 24 | "localeIdentifier": session.params["localeIdentifier"], 25 | "longitude": session.params["longitude"], 26 | "os_version": session.params["os_version"], 27 | "seqid": session.params["seqid"], 28 | "station_id": session.params["station_id"], 29 | "time": session.params["time"], 30 | "uid": session.params["uid"], 31 | }, 32 | headers: { 33 | "accept": session.headers["accept"], 34 | "accept-encoding": session.headers["accept-encoding"], 35 | "accept-language": session.headers["accept-language"], 36 | "content-type": "application/x-www-form-urlencoded", 37 | "cookie": session.headers["cookie"], 38 | "ddmc-api-version": session.headers["ddmc-api-version"], 39 | "ddmc-app-client-id": session.headers["ddmc-app-client-id"], 40 | "ddmc-build-version": session.headers["ddmc-build-version"], 41 | "ddmc-channel": session.headers["ddmc-channel"], 42 | "ddmc-city-number": session.headers["ddmc-city-number"], 43 | "ddmc-country-code": session.headers["ddmc-country-code"], 44 | "ddmc-device-id": session.headers["ddmc-device-id"], 45 | "ddmc-device-model": session.headers["ddmc-device-model"], 46 | "ddmc-device-name": session.headers["ddmc-device-name"], 47 | "ddmc-device-token": session.headers["ddmc-device-token"], 48 | "ddmc-idfa": session.headers["ddmc-idfa"], 49 | "ddmc-ip": session.headers["ddmc-ip"], 50 | "ddmc-language-code": session.headers["ddmc-language-code"], 51 | "ddmc-latitude": session.headers["ddmc-latitude"], 52 | "ddmc-locale-identifier": session.headers["ddmc-locale-identifier"], 53 | "ddmc-longitude": session.headers["ddmc-longitude"], 54 | "ddmc-os-version": session.headers["ddmc-os-version"], 55 | "ddmc-station-id": session.headers["ddmc-station-id"], 56 | "ddmc-uid": session.headers["ddmc-uid"], 57 | "time": session.headers["time"], 58 | "user-agent": session.headers["user-agent"], 59 | "im_secret": session.user["im_secret"], 60 | }, 61 | }))); 62 | 63 | if (result.data.success) { 64 | return result.data.data; 65 | } else { 66 | throw (result.data.msg || result.data.message); 67 | } 68 | }; -------------------------------------------------------------------------------- /service/dingdong/api/ios-native/cart_check_all.js: -------------------------------------------------------------------------------- 1 | module.exports = async (session) => { 2 | let result = ((await axios({ 3 | method: 'post', 4 | url: 'https://maicai.api.ddxq.mobi/cart/allCheck', 5 | data: { 6 | "ab_config": session.params["ab_config"], 7 | "api_version": session.params["api_version"], 8 | "app_client_id": session.params["app_client_id"], 9 | "app_type": session.params["app_type"], 10 | "buildVersion": session.params["buildVersion"], 11 | "channel": session.params["channel"], 12 | "city_number": session.params["city_number"], 13 | "countryCode": session.params["countryCode"], 14 | "device_id": session.params["device_id"], 15 | "device_model": session.params["device_model"], 16 | "device_name": session.params["device_name"], 17 | "device_token": session.params["device_token"], 18 | "idfa": session.params["idfa"], 19 | "ip": session.params["ip"], 20 | "is_check": 1, 21 | "is_filter": 0, 22 | "is_load": 1, 23 | "languageCode": session.params["languageCode"], 24 | "latitude": session.params["latitude"], 25 | "localeIdentifier": session.params["localeIdentifier"], 26 | "longitude": session.params["longitude"], 27 | "os_version": session.params["os_version"], 28 | "seqid": `1044641691`, 29 | "station_id": session.params["station_id"], 30 | "time": session.params["time"], 31 | "uid": session.params["uid"], 32 | }, 33 | headers: { 34 | "accept": session.headers["accept"], 35 | "accept-encoding": session.headers["accept-encoding"], 36 | "accept-language": session.headers["accept-language"], 37 | "content-type": "application/x-www-form-urlencoded", 38 | "cookie": session.headers["cookie"], 39 | "ddmc-api-version": session.headers["ddmc-api-version"], 40 | "ddmc-app-client-id": session.headers["ddmc-app-client-id"], 41 | "ddmc-build-version": session.headers["ddmc-build-version"], 42 | "ddmc-channel": session.headers["ddmc-channel"], 43 | "ddmc-city-number": session.headers["ddmc-city-number"], 44 | "ddmc-country-code": session.headers["ddmc-country-code"], 45 | "ddmc-device-id": session.headers["ddmc-device-id"], 46 | "ddmc-device-model": session.headers["ddmc-device-model"], 47 | "ddmc-device-name": session.headers["ddmc-device-name"], 48 | "ddmc-device-token": session.headers["ddmc-device-token"], 49 | "ddmc-idfa": session.headers["ddmc-idfa"], 50 | "ddmc-ip": session.headers["ddmc-ip"], 51 | "ddmc-language-code": session.headers["ddmc-language-code"], 52 | "ddmc-latitude": session.headers["ddmc-latitude"], 53 | "ddmc-locale-identifier": session.headers["ddmc-locale-identifier"], 54 | "ddmc-longitude": session.headers["ddmc-longitude"], 55 | "ddmc-os-version": session.headers["ddmc-os-version"], 56 | "ddmc-station-id": session.headers["ddmc-station-id"], 57 | "ddmc-uid": session.headers["ddmc-uid"], 58 | "time": session.headers["time"], 59 | "user-agent": session.headers["user-agent"], 60 | "im_secret": session.user["im_secret"], 61 | }, 62 | transformRequest: [function (data) { 63 | let ret = ''; 64 | for (let it in data) { 65 | ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'; 66 | } 67 | return ret; 68 | }], 69 | }))); 70 | 71 | if (result.data.success) { 72 | return result.data.data; 73 | } else { 74 | throw (result.data.msg || result.data.message); 75 | } 76 | }; -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 叮咚买菜抢菜助手(Node.js) 2 | ![available](https://img.shields.io/badge/%E9%A1%B9%E7%9B%AE%E5%BD%93%E5%89%8D%E7%8A%B6%E6%80%81-deprecated-red.svg "项目当前存在安全风险") ![api_version](https://img.shields.io/badge/API%20version-9.50.1-blue.svg "9.50.1") ![code_size](https://shields.io/github/languages/code-size/Runc2333/dingdong-helper-node) ![last_updayed](https://shields.io/github/last-commit/Runc2333/dingdong-helper-node) 3 | 4 | > Deprecated: 因部分用户无法理解本项目的出发点,自此commit后本仓库将转化为只读,且签名算法不可用。 5 | > 6 | > 感谢所有先前使用过、听说过、参与过的用户的支持,有缘江湖再见。 7 | 8 | 使用iOS客户端原生API,支持高峰期下单、支持捡漏、支持多账号、支持webhook通知(需自行实现对端) 9 | 10 | Telegram 交流群组:[点击加入](https://t.me/weneedfood) 11 | 12 | ## 写在前面 13 | 14 | 本项目旨在帮助更多的人能吃上饭,吃上饱饭。虽许可证允许,但我们*不支持*您通过本项目牟利。 15 | 16 | 若您在满足自身需求后仍有余力,请更多的帮助身边的人,尤其是独居老人。 17 | 18 | **写给叮咚买菜官方**:本项目已尽最大努力防止贵司利益受损,包括但不限于签名算法、接口参数等。如若贵司认为本项目侵犯了贵司的权益,请邮件联系 `i@runc321.com`,我们将会停用本项目。 19 | 20 | 少让程序员加班,从你我做起。 21 | 22 | ## 2022-05-01 重大更新 23 | 24 | > 后续更新日志不会写到这里,如确需了解,请查阅 commits 25 | > 26 | > 建议每次更新后都执行一次依赖安装,并执行一次任意 script 检查控制台是否提示更新配置文件 27 | 28 | **使用iOS原生客户端API,下单与iOS真机无差异,已测试可成功下单。** 29 | 30 | **请注意:** 更新后配置文件结构有更改,需要重新配置。 31 | 32 |      更新前的 Session 文件不继续适用于本项目,请重新获取。 33 | 34 | 特别感谢 [@IMLR](https://github.com/IMLR) 完成的`sesi`和`nars`签名算法分析。 35 | 36 | ## 配置项目 37 | 38 | ### 安装依赖 39 | 40 | > 若您没有 `node.js` 运行环境,请先安装 `node.js` 41 | > 42 | > 随后执行 `npm i yarn -g` (此命令可能需要管理员特权) 来全局安装`yarn` 43 | 44 | **在项目根目录启动终端,并执行如下命令以安装依赖:** 45 | 46 | 47 | ``` 48 | yarn 49 | ``` 50 | 51 | 52 | ### 更改设置 53 | 54 | 1、将项目`config/config.example.js`复制一份为`config/config.js` 55 | 56 | 2、修改其中提供的选项 57 | 58 | ```js 59 | webhook_url: '', // 下单成功通知url,暂无配套实现,可自行继承,详情请阅读后文 Webhook 部分 60 | thread_count: 2, // 下单时创建的线程数,建议不要超过3 61 | thread_interval: 100, // 线程创建间隔,建议不要低于100,单位ms 62 | submit_interval_min: 20 * 1000, // 随机最小请求间隔时间,单位ms 63 | submit_interval_max: 50 * 1000, // 随机最大请求间隔时间,单位ms 64 | minimal_order_money: 0, // 小于该金额的订单不会被提交 65 | api_channel: 'ios-native', // 可选 'ios-native', 'android-native' 或 'applet', 目前仅支持 'ios-native' 66 | profiles: [ 67 | { 68 | seq: 0, // 指示程序读取charles_sessions目录下的第几个文件 69 | im_secret: '',// 通过抓包获取,用于签名请求,获取请参见下文 70 | alias: '', // 配置文件别名,用于在下单成功时提示是哪个账号 71 | } 72 | ], 73 | ``` 74 | ### 获取 Session 75 | 76 | > 如果无法找到所列出的请求,请参见后文 iOS 设备 Charles 抓包帮助 77 | 78 | 1、在**iOS设备**上启动叮咚买菜APP 79 | 80 | 2、完成登录 81 | 82 | 3、启动Charles并完成抓包配置(需要配置SSL抓包) 83 | 84 | 4、点击“购物车”并刷新 85 | 86 | 5、在请求中找到`https://maicai.api.ddxq.mobi/cart/index` 87 | 88 | 6、右击该请求,选择`Export Session`,保存到项目`charles_sessions`文件夹下,文件类型请选择`JSON Session File (.chlsj)` 89 | 90 | ### 获取 im_secret 91 | 92 | 接续 获取 Session 第三步 93 | 94 | 4、点击“我的”并刷新 95 | 96 | 5、在请求中找到`https://sunquan.api.ddxq.mobi/api/v1/user/detail` 97 | 98 | 6、左击该请求,选择`Contents`选项卡,在下半部分选项卡中选择`JSON Text`视图 99 | 100 | 7、找到`user_info`下的`im_secret`字段,复制其值到配置文件中 101 | 102 | ## 可用执行选项 103 | 104 | ### 速抢模式 105 | 106 | > 建议抢菜高峰(06:00, 08:30)前一分钟启动,运行不要超过三分钟,否则账号会被风控 107 | > 108 | > 本项目不支持,也不会支持定时运行,所有执行选项都应在有人值守的情况下使用 109 | 110 | ``` 111 | yarn checkout:speed 112 | ``` 113 | 114 | ### 捡漏模式 115 | 116 | > 建议运行不要超过一小时,否则极易被封号 117 | > 118 | > 配置文件内可调请求间隔,默认20s ~ 50s随机 119 | > 120 | > 捡漏模式中的下单步骤不受请求间隔限制,默认逻辑为同时满足购物车有货和配送时间可用时疯狂下单,因此请勿在无人值守的情况下运行 121 | 122 | ``` 123 | yarn checkout:normal 124 | ``` 125 | 126 | ## iOS 设备 Charles 抓包帮助 127 | 128 | 因应用可主动选择不使用系统http代理,因此您需要一个第三方应用程序来实现抓包。 129 | 130 | 由 [@iiwen](https://github.com/iiwen) 撰写的 [完整图文抓包教程参见](https://www.jianshu.com/p/0191790ba30e) 131 | 132 | ## Webhook 133 | 134 | > 您需要根据所使用的客户端,自行修改源代码进行适配 135 | 136 | 默认情况下,在您配置好 `webhook_url` 后,下单成功时会向该地址发送一个 `POST` 请求, `body` 为 `JSON` 格式,包含如下字段: 137 | 138 | ```js 139 | { 140 | profile: '测试', // 配置文件中填写的别名 141 | price: 0.01, // 本次下单金额 142 | arrival_time: '14:30-22:00', // 本次下单的预约时间 143 | raw: { 144 | cart: ..., // 原始的购物车数据 145 | order: ..., // 原始的订单数据 146 | reserve_time: ..., // 原始的预约时间数据 147 | } 148 | } 149 | ``` 150 | 151 | 您可以通过修改 `/service/webhook.js` 来改变请求发送的方式、 `body` 的格式和内容,但入参(`{ profile, order, reserve_time, cart }`)不能修改。 152 | 153 | ## 下单成功提示音 154 | 155 | 下单成功时会播放`/assets/success.mp3`,默认为小猪佩奇,可自行替换。 156 | 157 | 如需关闭,请前往 `/scripts/checkout_cart.js` 自行注释相关代码。 158 | 159 | ## 免责声明 160 | 161 | 本程序使用 GNU General Public License v3.0 开源、不提供任何担保。使用本程序即表明,您知情并同意: 162 | 163 | - 使用本程序造成的一切后果由您本人承担,作者不会对您的任何损失负责,包括但不限于服务中断、Kernel Panic、机器无法开机或正常使用、数据丢失或硬件损坏、原子弹爆炸、第三次世界大战、SCP 基金会无法阻止 SCP-3125 引发的全球 MK 级现实重构等 164 | - 如若您修改了本程序并发布,您需要使用相同协议开源 165 | - 本程序中的所有签名算法不受项目许可证约束,不允许二次修改和分发。若确有需求,请在 Telegram 交流群内联系我。 -------------------------------------------------------------------------------- /service/dingdong/api/ios-native/get_multi_reserve_time.js: -------------------------------------------------------------------------------- 1 | module.exports = async (session, cart) => { 2 | let products = JSON.stringify(cart.new_order_product_list[0].products.map(product => { 3 | return { 4 | "sale_batches": { 5 | "batch_type": product.sale_batches ? product.sale_batches.batch_type : 0, 6 | }, 7 | "is_coupon_gift": 0, 8 | "id": product.id, 9 | "price": product.price, 10 | "is_booking": product.is_booking, 11 | "count": product.count, 12 | "small_image": product.small_image, 13 | "type": product.type, 14 | "origin_price": product.origin_price, 15 | "product_type": product.product_type, 16 | "product_name": product.product_name, 17 | }; 18 | })).replace(/"/g, '\\"'); 19 | let data = { 20 | "ab_config": `{"ETA_time_default_selection":"C1.1"}`, 21 | "api_version": session.params["api_version"], 22 | "app_client_id": session.params["app_client_id"], 23 | "app_type": session.params["app_type"], 24 | "buildVersion": session.params["buildVersion"], 25 | "channel": session.params["channel"], 26 | "city_number": session.params["city_number"], 27 | "countryCode": session.params["countryCode"], 28 | "device_id": session.params["device_id"], 29 | "device_model": session.params["device_model"], 30 | "device_name": session.params["device_name"], 31 | "device_token": session.params["device_token"], 32 | "idfa": session.params["idfa"], 33 | "ip": session.params["ip"], 34 | "languageCode": session.params["languageCode"], 35 | "latitude": session.params["latitude"], 36 | "localeIdentifier": session.params["localeIdentifier"], 37 | "longitude": session.params["longitude"], 38 | "os_version": session.params["os_version"], 39 | "seqid": session.params["seqid"], 40 | "station_id": session.params["station_id"], 41 | "time": session.params["time"], 42 | "uid": session.params["uid"], 43 | "address_id": session.user.address_id, 44 | "products": `["${products}"]`, 45 | }; 46 | let data_keys = Object.keys(data).sort(); 47 | let data_sorted = {}; 48 | for (let key of data_keys) { 49 | data_sorted[key] = data[key]; 50 | } 51 | let result = ((await axios({ 52 | method: 'post', 53 | url: 'https://maicai.api.ddxq.mobi/order/getMultiReserveTime', 54 | data: data_sorted, 55 | headers: { 56 | "accept": session.headers["accept"], 57 | "accept-encoding": session.headers["accept-encoding"], 58 | "accept-language": session.headers["accept-language"], 59 | "content-type": "application/x-www-form-urlencoded", 60 | "cookie": session.headers["cookie"], 61 | "ddmc-api-version": session.headers["ddmc-api-version"], 62 | "ddmc-app-client-id": session.headers["ddmc-app-client-id"], 63 | "ddmc-build-version": session.headers["ddmc-build-version"], 64 | "ddmc-channel": session.headers["ddmc-channel"], 65 | "ddmc-city-number": session.headers["ddmc-city-number"], 66 | "ddmc-country-code": session.headers["ddmc-country-code"], 67 | "ddmc-device-id": session.headers["ddmc-device-id"], 68 | "ddmc-device-model": session.headers["ddmc-device-model"], 69 | "ddmc-device-name": session.headers["ddmc-device-name"], 70 | "ddmc-device-token": session.headers["ddmc-device-token"], 71 | "ddmc-idfa": session.headers["ddmc-idfa"], 72 | "ddmc-ip": session.headers["ddmc-ip"], 73 | "ddmc-language-code": session.headers["ddmc-language-code"], 74 | "ddmc-latitude": session.headers["ddmc-latitude"], 75 | "ddmc-locale-identifier": session.headers["ddmc-locale-identifier"], 76 | "ddmc-longitude": session.headers["ddmc-longitude"], 77 | "ddmc-os-version": session.headers["ddmc-os-version"], 78 | "ddmc-station-id": session.headers["ddmc-station-id"], 79 | "ddmc-uid": session.headers["ddmc-uid"], 80 | "time": session.headers["time"], 81 | "user-agent": session.headers["user-agent"], 82 | "im_secret": session.user["im_secret"], 83 | }, 84 | transformRequest: [function (data) { 85 | let ret = ''; 86 | for (let it in data) { 87 | ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'; 88 | } 89 | return ret; 90 | }] 91 | }))); 92 | 93 | if (result.data.success) { 94 | return result.data.data; 95 | } else { 96 | throw (result.data.msg || result.data.message); 97 | } 98 | }; -------------------------------------------------------------------------------- /service/dingdong/api/ios-native/check_order.js: -------------------------------------------------------------------------------- 1 | module.exports = async (session, cart) => { 2 | let products = cart.new_order_product_list[0].products.map(v => { 3 | return { 4 | "id": v.id, 5 | "is_booking": v.is_booking, 6 | "total_money": v.total_price, 7 | "is_invoice": v.is_invoice ? true : false, 8 | "total_origin_money": v.total_origin_price, 9 | "category_path": v.category_path, 10 | "count": v.count, 11 | "type": v.type, 12 | "batch_type": v.sale_batches ? v.sale_batches.batch_type : 0, 13 | "is_coupon_gift": v.is_gift, 14 | "price": v.price, 15 | "order_sort": String(v.order_sort), 16 | "instant_rebate_money": v.instant_rebate_money, 17 | "activity_id": v.activity_id, 18 | "conditions_num": v.conditions_num, 19 | "price_type": String(v.price_type), 20 | "product_type": v.product_type, 21 | "origin_price": v.origin_price 22 | }; 23 | }); 24 | let result = ((await axios({ 25 | method: 'post', 26 | url: 'https://maicai.api.ddxq.mobi/order/checkOrder', 27 | data: { 28 | "ab_config": `{"ETA_time_default_selection":"C1.1"}`, 29 | "api_version": session.params["api_version"], 30 | "app_client_id": session.params["app_client_id"], 31 | "app_type": session.params["app_type"], 32 | "buildVersion": session.params["buildVersion"], 33 | "channel": session.params["channel"], 34 | "city_number": session.params["city_number"], 35 | "countryCode": session.params["countryCode"], 36 | "coupons_id": "", 37 | "device_id": session.params["device_id"], 38 | "device_model": session.params["device_model"], 39 | "device_name": session.params["device_name"], 40 | "device_token": session.params["device_token"], 41 | "freight_ticket_id": 'default', 42 | "idfa": session.params["idfa"], 43 | "ip": session.params["ip"], 44 | "is_buy_coupons": 0, 45 | "languageCode": session.params["languageCode"], 46 | "latitude": session.params["latitude"], 47 | "localeIdentifier": session.params["localeIdentifier"], 48 | "longitude": session.params["longitude"], 49 | "os_version": session.params["os_version"], 50 | "seqid": session.params["seqid"], 51 | "station_id": session.params["station_id"], 52 | "time": session.params["time"], 53 | "uid": session.params["uid"], 54 | "address_id": session.user.address_id, 55 | "user_ticket_id": 'default', 56 | "is_use_point": 0, 57 | "is_use_balance": 0, 58 | "is_buy_vip": 0, 59 | "packages": JSON.stringify([{ 60 | "reserved_time": { 61 | "time_biz_type": 0, 62 | }, 63 | "real_match_supply_order": cart.new_order_product_list[0].is_supply_order, 64 | "is_supply_order": cart.new_order_product_list[0].is_supply_order, 65 | "package_type": cart.new_order_product_list[0].package_type, 66 | "package_id": cart.new_order_product_list[0].package_id, 67 | "products": products, 68 | }]), 69 | "check_order_type": 0, 70 | }, 71 | headers: { 72 | "accept": session.headers["accept"], 73 | "accept-encoding": session.headers["accept-encoding"], 74 | "accept-language": session.headers["accept-language"], 75 | "content-type": "application/x-www-form-urlencoded", 76 | "cookie": session.headers["cookie"], 77 | "ddmc-api-version": session.headers["ddmc-api-version"], 78 | "ddmc-app-client-id": session.headers["ddmc-app-client-id"], 79 | "ddmc-build-version": session.headers["ddmc-build-version"], 80 | "ddmc-channel": session.headers["ddmc-channel"], 81 | "ddmc-city-number": session.headers["ddmc-city-number"], 82 | "ddmc-country-code": session.headers["ddmc-country-code"], 83 | "ddmc-device-id": session.headers["ddmc-device-id"], 84 | "ddmc-device-model": session.headers["ddmc-device-model"], 85 | "ddmc-device-name": session.headers["ddmc-device-name"], 86 | "ddmc-device-token": session.headers["ddmc-device-token"], 87 | "ddmc-idfa": session.headers["ddmc-idfa"], 88 | "ddmc-ip": session.headers["ddmc-ip"], 89 | "ddmc-language-code": session.headers["ddmc-language-code"], 90 | "ddmc-latitude": session.headers["ddmc-latitude"], 91 | "ddmc-locale-identifier": session.headers["ddmc-locale-identifier"], 92 | "ddmc-longitude": session.headers["ddmc-longitude"], 93 | "ddmc-os-version": session.headers["ddmc-os-version"], 94 | "ddmc-station-id": session.headers["ddmc-station-id"], 95 | "ddmc-uid": session.headers["ddmc-uid"], 96 | "time": session.headers["time"], 97 | "user-agent": session.headers["user-agent"], 98 | "im_secret": session.user["im_secret"], 99 | }, 100 | transformRequest: [function (data) { 101 | let ret = ''; 102 | for (let it in data) { 103 | ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'; 104 | } 105 | return ret; 106 | }], 107 | }))); 108 | 109 | if (result.data.success) { 110 | return result.data.data; 111 | } else { 112 | throw (result.data.msg || result.data.message || result.data.tips.limitMsg); 113 | } 114 | }; -------------------------------------------------------------------------------- /service/dingdong/api/ios-native/add_new_order.js: -------------------------------------------------------------------------------- 1 | module.exports = async (session, cart, order, reserve_time) => { 2 | if (order.order.total_money < config.dingdong.minimal_order_money) { 3 | throw (`订单金额不满足最低要求: ${order.order.total_money} 元`); 4 | } 5 | let package_order = { 6 | "payment_order": { 7 | "parent_order_sign": cart.parent_order_info.parent_order_sign, 8 | "price": order.order.total_money, 9 | "pay_type": 2, 10 | "receipt_without_sku": "0", 11 | "order_freight": order.order.freights[0].freight.freight_real_money, 12 | "is_use_balance": "0", 13 | "address_id": session.user.address_id, 14 | "current_position": [session.params["latitude"], session.params["longitude"]], 15 | "user_ticket_id": order.order.default_coupon._id, 16 | }, 17 | "packages": [{ 18 | "first_selected_big_time": "0", 19 | "products": cart.new_order_product_list[0].products.map(v => { 20 | return { 21 | "price": v.price, 22 | "batch_type": v.sale_batches ? v.sale_batches.batch_type : 0, 23 | "order_sort": v.order_sort, 24 | "cart_id": v.cart_id, 25 | "parent_id": v.parent_id, 26 | "count": v.count, 27 | "id": v.id, 28 | }; 29 | }), 30 | "reserved_time_end": reserve_time.reserved_time_end, 31 | "package_id": cart.new_order_product_list[0].package_id, 32 | "package_type": cart.new_order_product_list[0].package_type, 33 | "soon_arrival": "", 34 | "eta_trace_id": "", 35 | "reserved_time_start": reserve_time.reserved_time_start, 36 | "real_match_supply_order": false, 37 | "time_biz_type": 0, 38 | }] 39 | }; 40 | let result = ((await axios({ 41 | method: 'post', 42 | url: 'https://maicai.api.ddxq.mobi/order/addNewOrder', 43 | data: { 44 | "ab_config": `{"key_no_condition_barter":false}`, 45 | "api_version": session.params["api_version"], 46 | "app_client_id": session.params["app_client_id"], 47 | "app_type": session.params["app_type"], 48 | "buildVersion": session.params["buildVersion"], 49 | "channel": session.params["channel"], 50 | "city_number": session.params["city_number"], 51 | "clientDetail": ``, 52 | "countryCode": session.params["countryCode"], 53 | "device_id": session.params["device_id"], 54 | "device_model": session.params["device_model"], 55 | "device_name": session.params["device_name"], 56 | "device_token": session.params["device_token"], 57 | "idfa": session.params["idfa"], 58 | "ip": session.params["ip"], 59 | "languageCode": session.params["languageCode"], 60 | "latitude": session.params["latitude"], 61 | "localeIdentifier": session.params["localeIdentifier"], 62 | "longitude": session.params["longitude"], 63 | "os_version": session.params["os_version"], 64 | "package_order": JSON.stringify(package_order), 65 | "seqid": session.params["seqid"], 66 | "station_id": session.params["station_id"], 67 | "time": session.params["time"], 68 | "uid": session.params["uid"], 69 | }, 70 | headers: { 71 | "accept": session.headers["accept"], 72 | "accept-encoding": session.headers["accept-encoding"], 73 | "accept-language": session.headers["accept-language"], 74 | "content-type": "application/x-www-form-urlencoded", 75 | "cookie": session.headers["cookie"], 76 | "ddmc-api-version": session.headers["ddmc-api-version"], 77 | "ddmc-app-client-id": session.headers["ddmc-app-client-id"], 78 | "ddmc-build-version": session.headers["ddmc-build-version"], 79 | "ddmc-channel": session.headers["ddmc-channel"], 80 | "ddmc-city-number": session.headers["ddmc-city-number"], 81 | "ddmc-country-code": session.headers["ddmc-country-code"], 82 | "ddmc-device-id": session.headers["ddmc-device-id"], 83 | "ddmc-device-model": session.headers["ddmc-device-model"], 84 | "ddmc-device-name": session.headers["ddmc-device-name"], 85 | "ddmc-device-token": session.headers["ddmc-device-token"], 86 | "ddmc-idfa": session.headers["ddmc-idfa"], 87 | "ddmc-ip": session.headers["ddmc-ip"], 88 | "ddmc-language-code": session.headers["ddmc-language-code"], 89 | "ddmc-latitude": session.headers["ddmc-latitude"], 90 | "ddmc-locale-identifier": session.headers["ddmc-locale-identifier"], 91 | "ddmc-longitude": session.headers["ddmc-longitude"], 92 | "ddmc-os-version": session.headers["ddmc-os-version"], 93 | "ddmc-station-id": session.headers["ddmc-station-id"], 94 | "ddmc-uid": session.headers["ddmc-uid"], 95 | "time": session.headers["time"], 96 | "user-agent": session.headers["user-agent"], 97 | "im_secret": session.user["im_secret"], 98 | }, 99 | transformRequest: [function (data) { 100 | let ret = ''; 101 | for (let it in data) { 102 | ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'; 103 | } 104 | return ret; 105 | }], 106 | }))); 107 | 108 | if (result.data.success) { 109 | return result.data.data; 110 | } else { 111 | throw (result.data.msg || result.data.message || result.data.tips.limitMsg); 112 | } 113 | }; -------------------------------------------------------------------------------- /service/session_parser.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs'); 2 | const path = require('path'); 3 | const tools = require('../utils/tools'); 4 | const crypto = require('crypto'); 5 | 6 | const load_profile = (profile) => { 7 | let req_data; 8 | try { 9 | req_data = JSON.parse(fs.readFileSync(path.join(__dirname, '../charles_sessions', fs.readdirSync(path.join(__dirname, '../charles_sessions')).filter(v => /\.chlsj$/.test(v))[profile.seq]), 'utf8')); 10 | } catch (e) { 11 | logger.e(e); 12 | logger.e('请检查您的配置文件是否正确, charles_session 目录下是否存在 .chlsj(JSON Session File) 文件'); 13 | process.exit(1); 14 | } 15 | 16 | const user = { 17 | address_id: '', 18 | group_config_id: '', 19 | im_secret: profile.im_secret, 20 | }; 21 | 22 | let query; 23 | try { 24 | query = tools.parse_query(req_data[0].query); 25 | } catch (e) { 26 | logger.e(e); 27 | logger.e('请检查您的配置文件是否正确, charles_session 目录下是否存在 .chlsj(JSON Session File) 文件'); 28 | process.exit(1); 29 | } 30 | for (let key in query) { 31 | query[key] = decodeURIComponent(query[key]); 32 | } 33 | const query_locator = (name) => { 34 | if (query[name] !== undefined) { 35 | return query[name]; 36 | } 37 | logger.w(`[${profile.alias}] 未能从 session 文件提取需要的 query: ${name}, 已返回空字符串`); 38 | logger.w(`[${profile.alias}] 请检查您导出的 session 文件是否正确`); 39 | logger.w(`[${profile.alias}] 如可正常运行,请忽略`); 40 | return ''; 41 | }; 42 | const params = new Proxy({ 43 | "ab_config": query_locator("ab_config"), 44 | "api_version": query_locator("api_version"), 45 | "app_client_id": query_locator("app_client_id"), 46 | "app_type": query_locator("app_type"), 47 | "buildVersion": query_locator("buildVersion"), 48 | "channel": query_locator("channel"), 49 | "city_number": query_locator("city_number"), 50 | "countryCode": query_locator("countryCode"), 51 | "device_id": query_locator("device_id"), 52 | "device_model": query_locator("device_model"), 53 | "device_name": query_locator("device_name"), 54 | "device_token": query_locator("device_token"), 55 | "idfa": query_locator("idfa"), 56 | "ip": query_locator("ip"), 57 | "is_filter": query_locator("is_filter"), 58 | "is_load": query_locator("is_load"), 59 | "languageCode": query_locator("languageCode"), 60 | "latitude": query_locator("latitude"), 61 | "localeIdentifier": query_locator("localeIdentifier"), 62 | "longitude": query_locator("longitude"), 63 | "os_version": query_locator("os_version"), 64 | "seqid": query_locator("seqid"), 65 | "sign": query_locator("sign"), 66 | "station_id": query_locator("station_id"), 67 | "time": query_locator("time"), 68 | "uid": query_locator("uid"), 69 | }, { 70 | get (target, key) { 71 | if (key == 'time') { 72 | return Math.round(new Date().getTime() / 1000); 73 | } 74 | if (target[key] !== undefined) { 75 | return target[key]; 76 | } else { 77 | if (typeof key !== "symbol") { 78 | logger.d(`尝试获取不存在的 Param: ${key}`); 79 | } 80 | return ''; 81 | } 82 | }, 83 | }); 84 | 85 | let header; 86 | try { 87 | header = req_data[0].request.header.headers.map(v => { 88 | return { 89 | name: decodeURIComponent(v.name), 90 | value: decodeURIComponent(v.value), 91 | }; 92 | }); 93 | } catch (e) { 94 | logger.e(e); 95 | logger.e('请检查您的配置文件是否正确, charles_session 目录下是否存在 .chlsj(JSON Session File) 文件'); 96 | process.exit(1); 97 | } 98 | const header_locator = (name) => { 99 | let target = header.find(item => item.name.toLowerCase() == name.toLowerCase()); 100 | if (target) return target.value; 101 | logger.w(`[${profile.alias}] 未能从 session 文件提取需要的 header: ${name}, 已返回空字符串`); 102 | logger.w(`[${profile.alias}] 请检查您导出的 session 文件是否正确`); 103 | logger.w(`[${profile.alias}] 如可正常运行,请忽略`); 104 | return ''; 105 | }; 106 | const headers = new Proxy({ 107 | "ddmc-city-number": header_locator("ddmc-city-number"), 108 | "ddmc-locale-identifier": header_locator("ddmc-locale-identifier"), 109 | "user-agent": header_locator("user-agent"), 110 | "ddmc-device-token": header_locator("ddmc-device-token"), 111 | "cookie": header_locator("cookie"), 112 | "ddmc-api-version": header_locator("ddmc-api-version"), 113 | "ddmc-build-version": header_locator("ddmc-build-version"), 114 | "ddmc-idfa": header_locator("ddmc-idfa"), 115 | "ddmc-longitude": header_locator("ddmc-longitude"), 116 | "ddmc-latitude": header_locator("ddmc-latitude"), 117 | "ddmc-app-client-id": header_locator("ddmc-app-client-id"), 118 | "ddmc-device-name": header_locator("ddmc-device-name"), 119 | "ddmc-uid": header_locator("ddmc-uid"), 120 | "accept-language": header_locator("accept-language"), 121 | "ddmc-device-model": header_locator("ddmc-device-model"), 122 | "ddmc-channel": header_locator("ddmc-channel"), 123 | "ddmc-country-code": header_locator("ddmc-country-code"), 124 | "ddmc-device-id": header_locator("ddmc-device-id"), 125 | "ddmc-ip": header_locator("ddmc-ip"), 126 | "ddmc-station-id": header_locator("ddmc-station-id"), 127 | "ddmc-language-code": header_locator("ddmc-language-code"), 128 | "accept": header_locator("accept"), 129 | "accept-encoding": header_locator("accept-encoding"), 130 | "ddmc-os-version": header_locator("ddmc-os-version"), 131 | im_secret: profile.im_secret, 132 | }, { 133 | get (target, key) { 134 | if (key == 'time') { 135 | let time = Math.round(new Date().getTime() / 1000); 136 | return `${time},${crypto.createHash('md5').update(`private_key=${user.im_secret}&time=${time}`).digest('hex')}`; 137 | } 138 | if (target[key] !== undefined) { 139 | return target[key]; 140 | } else { 141 | if (typeof key !== "symbol") { 142 | logger.d(`尝试获取不存在的 Header: ${key}`); 143 | } 144 | return ''; 145 | } 146 | } 147 | }); 148 | 149 | return { 150 | params, 151 | headers, 152 | user, 153 | }; 154 | }; 155 | 156 | 157 | module.exports = { 158 | load_profile 159 | }; -------------------------------------------------------------------------------- /utils/logger.js: -------------------------------------------------------------------------------- 1 | const dateformat = require("dateformat"); 2 | const fs = require("fs-extra"); 3 | const path = require("path"); 4 | 5 | // Hack fs-extra module. 6 | let append_to_log = (data) => { 7 | try { 8 | fs.ensureFileSync(path.join( 9 | config.log.folder, 10 | `${config.log.log_split ? dateformat((new Date()), 'yyyy-mm-dd') : 'server'}.log` 11 | )); 12 | } catch (e) { 13 | throw new Error('Unable to create log file:' + e); 14 | } 15 | try { 16 | fs.appendFileSync(path.join( 17 | config.log.folder, 18 | `${config.log.log_split ? dateformat((new Date()), 'yyyy-mm-dd') : 'server'}.log` 19 | ), data); 20 | } catch (e) { 21 | throw new Error('Unable to append log file:' + e); 22 | } 23 | }; 24 | 25 | let t = (() => { 26 | let conditons = ['trace']; 27 | if (conditons.includes(config.log.console_level) && conditons.includes(config.log.log_level)) { 28 | return (msg) => { 29 | String(msg).split('\n').forEach((line) => { 30 | console.log(`[${dateformat((new Date()), 'yyyy-mm-dd HH:MM:ss')}] ${"\033[40;97m"}[TRACE]${"\033[0m"} ${line}`); 31 | append_to_log(`[${dateformat((new Date()), 'yyyy-mm-dd HH:MM:ss')}] [TRACE] ${line}\n`); 32 | }); 33 | }; 34 | } else if (conditons.includes(config.log.console_level)) { 35 | return (msg) => { 36 | String(msg).split('\n').forEach((line) => { 37 | console.log(`[${dateformat((new Date()), 'yyyy-mm-dd HH:MM:ss')}] ${"\033[40;97m"}[TRACE]${"\033[0m"} ${line}`); 38 | }); 39 | }; 40 | } else if (conditons.includes(config.log.log_level)) { 41 | return (msg) => { 42 | String(msg).split('\n').forEach((line) => { 43 | append_to_log(`[${dateformat((new Date()), 'yyyy-mm-dd HH:MM:ss')}] [TRACE] ${line}\n`); 44 | }); 45 | }; 46 | } else { 47 | return () => { }; 48 | } 49 | })(), trace = t; 50 | 51 | let d = (() => { 52 | let conditons = ['trace', 'debug']; 53 | if (conditons.includes(config.log.console_level) && conditons.includes(config.log.log_level)) { 54 | return (msg) => { 55 | String(msg).split('\n').forEach((line) => { 56 | console.log(`[${dateformat((new Date()), 'yyyy-mm-dd HH:MM:ss')}] ${"\033[40;97m"}[DEBUG]${"\033[0m"} ${line}`); 57 | append_to_log(`[${dateformat((new Date()), 'yyyy-mm-dd HH:MM:ss')}] [DEBUG] ${line}\n`); 58 | }); 59 | }; 60 | } else if (conditons.includes(config.log.console_level)) { 61 | return (msg) => { 62 | String(msg).split('\n').forEach((line) => { 63 | console.log(`[${dateformat((new Date()), 'yyyy-mm-dd HH:MM:ss')}] ${"\033[40;97m"}[DEBUG]${"\033[0m"} ${line}`); 64 | }); 65 | }; 66 | } else if (conditons.includes(config.log.log_level)) { 67 | return (msg) => { 68 | String(msg).split('\n').forEach((line) => { 69 | append_to_log(`[${dateformat((new Date()), 'yyyy-mm-dd HH:MM:ss')}] [DEBUG] ${line}\n`); 70 | }); 71 | }; 72 | } else { 73 | return () => { }; 74 | } 75 | })(), debug = d; 76 | 77 | let i = (() => { 78 | let conditons = ['trace', 'debug', 'info']; 79 | if (conditons.includes(config.log.console_level) && conditons.includes(config.log.log_level)) { 80 | return (msg) => { 81 | String(msg).split('\n').forEach((line) => { 82 | console.log(`[${dateformat((new Date()), 'yyyy-mm-dd HH:MM:ss')}] [INFO] ${line}`); 83 | append_to_log(`[${dateformat((new Date()), 'yyyy-mm-dd HH:MM:ss')}] [INFO] ${line}\n`); 84 | }); 85 | }; 86 | } else if (conditons.includes(config.log.console_level)) { 87 | return (msg) => { 88 | String(msg).split('\n').forEach((line) => { 89 | console.log(`[${dateformat((new Date()), 'yyyy-mm-dd HH:MM:ss')}] [INFO] ${line}`); 90 | }); 91 | }; 92 | } else if (conditons.includes(config.log.log_level)) { 93 | return (msg) => { 94 | String(msg).split('\n').forEach((line) => { 95 | append_to_log(`[${dateformat((new Date()), 'yyyy-mm-dd HH:MM:ss')}] [INFO] ${line}\n`); 96 | }); 97 | }; 98 | } else { 99 | return () => { }; 100 | } 101 | })(), info = i; 102 | 103 | let w = (() => { 104 | let conditons = ['trace', 'debug', 'info', 'warn']; 105 | if (conditons.includes(config.log.console_level) && conditons.includes(config.log.log_level)) { 106 | return (msg) => { 107 | String(msg).split('\n').forEach((line) => { 108 | console.log(`[${dateformat((new Date()), 'yyyy-mm-dd HH:MM:ss')}] ${"\033[44;97m"}[WARN]${"\033[0m"} ${line}`); 109 | append_to_log(`[${dateformat((new Date()), 'yyyy-mm-dd HH:MM:ss')}] [WARN] ${line}\n`); 110 | }); 111 | }; 112 | } else if (conditons.includes(config.log.console_level)) { 113 | return (msg) => { 114 | String(msg).split('\n').forEach((line) => { 115 | console.log(`[${dateformat((new Date()), 'yyyy-mm-dd HH:MM:ss')}] ${"\033[44;97m"}[WARN]${"\033[0m"} ${line}`); 116 | }); 117 | }; 118 | } else if (conditons.includes(config.log.log_level)) { 119 | return (msg) => { 120 | String(msg).split('\n').forEach((line) => { 121 | append_to_log(`[${dateformat((new Date()), 'yyyy-mm-dd HH:MM:ss')}] [WARN] ${line}\n`); 122 | }); 123 | }; 124 | } else { 125 | return () => { }; 126 | } 127 | })(), warn = w; 128 | 129 | let e = (() => { 130 | let conditons = ['trace', 'debug', 'info', 'warn', 'error']; 131 | if (conditons.includes(config.log.console_level) && conditons.includes(config.log.log_level)) { 132 | return (msg) => { 133 | String(msg).split('\n').forEach((line) => { 134 | console.log(`[${dateformat((new Date()), 'yyyy-mm-dd HH:MM:ss')}] ${"\033[41;97m"}[ERROR]${"\033[0m"} ${line}`); 135 | append_to_log(`[${dateformat((new Date()), 'yyyy-mm-dd HH:MM:ss')}] [ERROR] ${line}\n`); 136 | }); 137 | }; 138 | } else if (conditons.includes(config.log.console_level)) { 139 | return (msg) => { 140 | String(msg).split('\n').forEach((line) => { 141 | console.log(`[${dateformat((new Date()), 'yyyy-mm-dd HH:MM:ss')}] ${"\033[41;97m"}[ERROR]${"\033[0m"} ${line}`); 142 | }); 143 | }; 144 | } else if (conditons.includes(config.log.log_level)) { 145 | return (msg) => { 146 | String(msg).split('\n').forEach((line) => { 147 | append_to_log(`[${dateformat((new Date()), 'yyyy-mm-dd HH:MM:ss')}] [ERROR] ${line}\n`); 148 | }); 149 | }; 150 | } else { 151 | return () => { }; 152 | } 153 | })(), error = e; 154 | 155 | if (!config.log.enable) { 156 | t = trace = d = debug = i = info = w = warn = e = error = () => { }; 157 | } 158 | 159 | module.exports = { 160 | t, 161 | trace, 162 | d, 163 | debug, 164 | i, 165 | info, 166 | w, 167 | warn, 168 | e, 169 | error, 170 | }; -------------------------------------------------------------------------------- /scripts/checkout_cart.js: -------------------------------------------------------------------------------- 1 | require('../config/config'); 2 | require('../utils/autoloader'); 3 | 4 | const path = require('path'); 5 | const player = require('sound-play'); 6 | 7 | const ddmc = require('../service/dingdong'); 8 | const webhook = require('../service/webhook'); 9 | const { load_profile } = require('../service/session_parser'); 10 | const { EventEmitter } = require('events'); 11 | 12 | let speedcheck = process.argv[2] === 'speedcheck'; 13 | 14 | const get_address = async (token) => { 15 | let address; 16 | while (!address) { 17 | try { 18 | address = await ddmc.get_address(token); 19 | } catch (e) { 20 | address = undefined; 21 | logger.e(`获取地址列表失败: ${e}`); 22 | if (/您的访问已过期/.test(e)) process.exit(1); 23 | if (!speedcheck) await tools.sleep(tools.rand_between(config.dingdong.submit_interval_min, config.dingdong.submit_interval_max)); 24 | } 25 | } 26 | return address; 27 | }; 28 | 29 | const get_cart = async (token) => { 30 | let cart; 31 | while (!cart) { 32 | try { 33 | await ddmc.cart_check_all(token); 34 | cart = await ddmc.get_cart(token); 35 | if (cart.new_order_product_list.length > 0) { 36 | logger.i(`购物车商品更新: 共 ${cart.new_order_product_list[0].total_count} 件`); 37 | } else { 38 | throw ('购物车无有货商品'); 39 | } 40 | } catch (e) { 41 | cart = undefined; 42 | logger.e(`获取购物车内容失败: ${e}`); 43 | if (e.stack) logger.d(e.stack); 44 | if (!speedcheck) await tools.sleep(tools.rand_between(config.dingdong.submit_interval_min, config.dingdong.submit_interval_max)); 45 | } 46 | } 47 | return cart; 48 | }; 49 | 50 | const get_reserve_time = async (token, cart) => { 51 | let reserve_time; 52 | while (!reserve_time) { 53 | try { 54 | let resp = await ddmc.get_multi_reserve_time(token, cart); 55 | for (let time of resp[0].time[0].times) { 56 | if (!time.fullFlag && !time.arrival_time_msg.includes('尽快')) { 57 | reserve_time = { 58 | reserved_time_start: time.start_timestamp, 59 | reserved_time_end: time.end_timestamp, 60 | time_text: time.arrival_time_msg, 61 | }; 62 | break; 63 | } 64 | } 65 | if (!reserve_time) { 66 | throw ('没有可预约的时间'); 67 | } 68 | } catch (e) { 69 | reserve_time = undefined; 70 | logger.e(`获取预约时间失败: ${e}`); 71 | if (e.stack) logger.d(e.stack); 72 | if (!speedcheck) await tools.sleep(tools.rand_between(config.dingdong.submit_interval_min, config.dingdong.submit_interval_max)); 73 | } 74 | } 75 | logger.i(`预约时间更新: ${reserve_time.time_text}`); 76 | return reserve_time; 77 | }; 78 | 79 | const check_order = async (token, cart, reserve_time) => { 80 | let order; 81 | while (!order) { 82 | try { 83 | order = await ddmc.check_order(token, cart, reserve_time); 84 | } catch (e) { 85 | order = undefined; 86 | logger.e(`获取订单失败: ${e}`); 87 | if (e && e.stack) logger.e(e.stack); 88 | if (String(e).trim().length === 0) continue; 89 | if (!speedcheck) await tools.sleep(100); 90 | } 91 | } 92 | logger.i(`订单信息更新: 总计: ${order.order.total_money} 元`); 93 | return order; 94 | }; 95 | 96 | (async () => { 97 | if (speedcheck) { 98 | if (config.dingdong.thread_count === undefined) { 99 | logger.w(`未设置提交订单并发数,请检查您的配置文件。本次运行将使用默认值: 2`); 100 | } else { 101 | logger.i(`当前提交订单并发数: ${config.dingdong.thread_count}`); 102 | } 103 | if (config.dingdong.thread_interval === undefined) { 104 | logger.w(`未设置线程创建延迟,请检查您的配置文件。本次运行将使用默认值: 100 ms`); 105 | } else { 106 | logger.i(`当前线程创建延迟: ${config.dingdong.thread_interval} ms`); 107 | } 108 | } 109 | for (let profile of config.dingdong.profiles) { 110 | (async () => { 111 | let session = load_profile(profile); 112 | // Rewrite station id and address id as default address 113 | let address = await get_address(session); 114 | let default_address = address.valid_address.find((addr) => { 115 | return addr.is_default; 116 | }); 117 | if (!default_address) { 118 | logger.e(`[${profile.alias}] 没有设置默认地址,请先设置`); 119 | process.exit(1); 120 | } 121 | let [longitude, latitude] = default_address.location.location; 122 | session.params.station_id = default_address.station_id; 123 | session.params.city_number = default_address.city_number; 124 | session.params.longitude = longitude; 125 | session.params.latitude = latitude; 126 | session.headers["ddmc-station-id"] = default_address.station_id; 127 | session.headers["ddmc-city-number"] = default_address.city_number; 128 | session.headers["ddmc-longitude"] = longitude; 129 | session.headers["ddmc-latitude"] = latitude; 130 | session.user.address_id = default_address.id; 131 | logger.i(`[${profile.alias}] 当前默认地址 : ${default_address.location.address}`); 132 | // Tring to make order 133 | let cart = await get_cart(session); 134 | let reserve_time = await get_reserve_time(session, cart); 135 | let order = await check_order(session, cart, reserve_time); 136 | let success = false; 137 | let promise_list = []; 138 | let thread_count = speedcheck ? (config.dingdong.thread_count || 2) : 1; 139 | let thread_interval = speedcheck ? (config.dingdong.thread_interval || 100) : 100; 140 | let emitter = new EventEmitter(); 141 | const submit_order = async () => { 142 | let local_success = false; 143 | // Refresh flags to avoid duplicate refresh 144 | let reserve_time_already_refreshed = false; 145 | emitter.on('reserve_time_refresh', () => { reserve_time_already_refreshed = true; }); 146 | let cart_already_refreshed = false; 147 | emitter.on('cart_refresh', () => { cart_already_refreshed = true; }); 148 | while (!success) { 149 | logger.i(`[${profile.alias}] 尝试下单 ${cart.new_order_product_list[0].total_count} 件商品 总计: ${order.order.total_money} 元 送达时间: ${reserve_time.time_text}`); 150 | try { 151 | await ddmc.add_new_order(session, cart, order, reserve_time); 152 | success = true; 153 | local_success = true; 154 | } catch (e) { 155 | logger.e(`[${profile.alias}] 下单失败: ${e}`); 156 | if (String(e).includes('时') && !reserve_time_already_refreshed) { 157 | // Reserve time changed, refresh 158 | reserve_time = await get_reserve_time(session, cart); 159 | order = await check_order(session, cart, reserve_time); 160 | emitter.emit('reserve_time_refresh'); 161 | } 162 | if ((String(e).includes('售罄') || String(e).includes('缺货') || String(e).includes('暂未营业') || String(e).includes('订单金额不满足最低要求')) && !cart_already_refreshed) { 163 | // Cart changed, refresh 164 | await ddmc.cart_check_all(session); 165 | cart = await get_cart(session); 166 | order = await check_order(session, cart, reserve_time); 167 | emitter.emit('cart_refresh'); 168 | } 169 | // Reset refresh flag 170 | reserve_time_already_refreshed = false; 171 | cart_already_refreshed = false; 172 | } 173 | // Success logic 174 | if (local_success) { 175 | // Send notification to webhook 176 | try { 177 | if (config.dingdong.webhook_url) { 178 | await webhook({ profile, cart, order, reserve_time }); 179 | logger.i(`[${profile.alias}] 已调用 webhook 方法`); 180 | } 181 | } catch (e) { 182 | logger.e(`[${profile.alias}] 调用 Webhook 方法时出现错误: ${e}`); 183 | logger.e(`[${profile.alias}] 请检查您的 webhook_url 是否正确, /service/webhook.js 是否编写正确, 接口状态是否正常`); 184 | if (e.stack) logger.d(e.stack); 185 | } 186 | // Play notification sound 187 | try { 188 | player.play(path.join(__dirname, '..', 'assets', "success.mp3"), 1); 189 | } catch (e) { 190 | logger.e(`播放提示音失败: ${e}`); 191 | if (e.stack) logger.d(e.stack); 192 | } 193 | logger.i(`[${profile.alias}] 下单成功`); 194 | if (!speedcheck) { 195 | // Loop when in normal mode 196 | success = false; // Reset success flag 197 | // Refresh cart and reserve time 198 | cart = await get_cart(session); 199 | reserve_time = await get_reserve_time(session, cart); 200 | order = await check_order(session, cart, reserve_time); 201 | continue; // Continue loop 202 | } 203 | } 204 | if (!speedcheck) await tools.sleep(200); 205 | } 206 | }; 207 | // Create threads 208 | for (let i = 0; i < thread_count; i++) { 209 | promise_list.push(submit_order()); 210 | await tools.sleep(thread_interval); 211 | } 212 | await Promise.all(promise_list); 213 | })(); 214 | if (!speedcheck) await tools.sleep(1000); 215 | } 216 | })(); -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------