|
|
@@ -1,11 +1,8 @@
|
|
|
const axios = require("axios");
|
|
|
const qs = require("qs");
|
|
|
const encryptUtil = require("./encryptUtil");
|
|
|
-const { Producer, PushConsumer } = require("apache-rocketmq");
|
|
|
-
|
|
|
-const producer = new Producer("my-producer-dev", "test", {
|
|
|
- nameServer: "120.24.204.226:9876",
|
|
|
-});
|
|
|
+const fs = require("fs");
|
|
|
+const queue = require("queue");
|
|
|
|
|
|
axios.defaults.baseURL = "https://test.raex.vip";
|
|
|
axios.interceptors.request.use(
|
|
|
@@ -40,51 +37,69 @@ axios
|
|
|
)
|
|
|
.then((res) => {
|
|
|
axios.defaults.headers["Authorization"] = "Bearer " + res.data;
|
|
|
- producer.start(function (err) {
|
|
|
- if (err) {
|
|
|
- console.log(err);
|
|
|
- } else {
|
|
|
- start();
|
|
|
- }
|
|
|
- });
|
|
|
+ start();
|
|
|
})
|
|
|
.catch((e) => {
|
|
|
console.log(e.response);
|
|
|
});
|
|
|
+let orders = [];
|
|
|
|
|
|
-const createOrder = () => {
|
|
|
- let params = {
|
|
|
- collectionId: 151602,
|
|
|
- qty: 1,
|
|
|
- couponId: "",
|
|
|
- invitor: "",
|
|
|
- };
|
|
|
- params.sign = encryptUtil.encrypt(
|
|
|
- qs.stringify({ ...params, ts: new Date().getTime() })
|
|
|
- );
|
|
|
- axios.post("/order/mqCreate", qs.stringify(params)).then((res) => {
|
|
|
- let i = setInterval(() => {
|
|
|
- axios.get("/order/createResult?id=" + res.data.id).then((res) => {
|
|
|
+const queryResult = (id, i, cb) => {
|
|
|
+ if (i > 5) {
|
|
|
+ cb();
|
|
|
+ } else {
|
|
|
+ axios
|
|
|
+ .get("/order/createResult?id=" + id)
|
|
|
+ .then((res) => {
|
|
|
if (res.data) {
|
|
|
- clearInterval(i);
|
|
|
+ cb(null, res.data.data);
|
|
|
console.log(res.data.data);
|
|
|
- producer.send(
|
|
|
- "order-notify-topic-test",
|
|
|
- JSON.stringify({
|
|
|
- orderId: res.data.data.id,
|
|
|
- payMethod: "ALIPAY",
|
|
|
- transactionId: new Date().getTime(),
|
|
|
- time: new Date().getTime(),
|
|
|
- })
|
|
|
- );
|
|
|
+ } else {
|
|
|
+ setTimeout(() => {
|
|
|
+ queryResult(id, ++i, cb);
|
|
|
+ }, 1000);
|
|
|
}
|
|
|
+ })
|
|
|
+ .catch((e) => {
|
|
|
+ setTimeout(() => {
|
|
|
+ queryResult(id, ++i, cb);
|
|
|
+ }, 1000);
|
|
|
});
|
|
|
- }, 2000);
|
|
|
- });
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
function start() {
|
|
|
+ const q = queue({ results: [], concurrency: 1000 });
|
|
|
for (let i = 0; i < 1; i++) {
|
|
|
- createOrder();
|
|
|
+ q.push((cb) => {
|
|
|
+ let params = {
|
|
|
+ collectionId: 151602,
|
|
|
+ qty: 1,
|
|
|
+ couponId: "",
|
|
|
+ invitor: "",
|
|
|
+ };
|
|
|
+ params.sign = encryptUtil.encrypt(
|
|
|
+ qs.stringify({ ...params, ts: new Date().getTime() })
|
|
|
+ );
|
|
|
+ axios
|
|
|
+ .post("/order/mqCreate", qs.stringify(params))
|
|
|
+ .then((res) => {
|
|
|
+ queryResult(res.data.id, 0, cb);
|
|
|
+ })
|
|
|
+ .catch((e) => {
|
|
|
+ cb();
|
|
|
+ });
|
|
|
+ });
|
|
|
}
|
|
|
+ q.start((err) => {
|
|
|
+ console.log("all done", q.results);
|
|
|
+ fs.writeFileSync(
|
|
|
+ "orders.json",
|
|
|
+ JSON.stringify(
|
|
|
+ q.results.map((i) => i[0]),
|
|
|
+ null,
|
|
|
+ 4
|
|
|
+ )
|
|
|
+ );
|
|
|
+ });
|
|
|
}
|