update at 2020-12-18 13:44:38 by ehlxr
This commit is contained in:
parent
fe1a8881dd
commit
b838ca2e3d
@ -33,7 +33,7 @@ import java.util.concurrent.FutureTask;
|
|||||||
* Created by ehlxr on 2017/4/11.
|
* Created by ehlxr on 2017/4/11.
|
||||||
*/
|
*/
|
||||||
public class TestFutureCahe<K, V> {
|
public class TestFutureCahe<K, V> {
|
||||||
private final ConcurrentHashMap<K, Future<V>> cacheMap = new ConcurrentHashMap<K, Future<V>>();
|
private final ConcurrentHashMap<K, Future<V>> cacheMap = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
final TestFutureCahe<String, String> TestGuaVA = new TestFutureCahe<String, String>();
|
final TestFutureCahe<String, String> TestGuaVA = new TestFutureCahe<String, String>();
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.github.ehlxr;
|
package io.github.ehlxr.test;
|
||||||
//
|
//
|
||||||
// import cn.ceres.did.client.SdkClient;
|
// import cn.ceres.did.client.SdkClient;
|
||||||
// import cn.ceres.did.sdk.SdkProto;
|
// import cn.ceres.did.sdk.SdkProto;
|
@ -22,7 +22,7 @@
|
|||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.github.ehlxr;
|
package io.github.ehlxr.test;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
142
src/main/java/io/github/ehlxr/test/TestCompletableFuture.java
Normal file
142
src/main/java/io/github/ehlxr/test/TestCompletableFuture.java
Normal file
@ -0,0 +1,142 @@
|
|||||||
|
/*
|
||||||
|
* The MIT License (MIT)
|
||||||
|
*
|
||||||
|
* Copyright © 2020 xrv <xrg@live.com>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.github.ehlxr.test;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.concurrent.Future;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* https://colobu.com/2016/02/29/Java-CompletableFuture/
|
||||||
|
*
|
||||||
|
* @author ehlxr
|
||||||
|
* @since 2020-12-18 10:12.
|
||||||
|
*/
|
||||||
|
public class TestCompletableFuture {
|
||||||
|
// public static void main(String[] args) throws ExecutionException, InterruptedException {
|
||||||
|
// ExecutorService es = Executors.newFixedThreadPool(10);
|
||||||
|
// Future<Integer> f = es.submit(() -> {
|
||||||
|
// // 长时间的异步计算
|
||||||
|
// Thread.sleep(3000);
|
||||||
|
// // 然后返回结果
|
||||||
|
// return 100;
|
||||||
|
// });
|
||||||
|
// // while (!f.isDone());
|
||||||
|
// System.out.println(f.get());
|
||||||
|
// }
|
||||||
|
|
||||||
|
// public static CompletableFuture<Integer> compute() {
|
||||||
|
// return new CompletableFuture<>();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public static void main(String[] args) throws Exception {
|
||||||
|
// final CompletableFuture<Integer> f = compute();
|
||||||
|
// class Client extends Thread {
|
||||||
|
// final CompletableFuture<Integer> f;
|
||||||
|
//
|
||||||
|
// Client(String threadName, CompletableFuture<Integer> f) {
|
||||||
|
// super(threadName);
|
||||||
|
// this.f = f;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// @Override
|
||||||
|
// public void run() {
|
||||||
|
// try {
|
||||||
|
// System.out.println(this.getName() + ": " + f.get());
|
||||||
|
// } catch (InterruptedException | ExecutionException e) {
|
||||||
|
// e.printStackTrace();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// new Client("Client1", f).start();
|
||||||
|
// new Client("Client2", f).start();
|
||||||
|
// System.out.println("waiting");
|
||||||
|
// // 完成,客户端 get() 阻塞通过
|
||||||
|
// f.complete(100);
|
||||||
|
// //f.completeExceptionally(new Exception());
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
private static final long t = System.currentTimeMillis();
|
||||||
|
|
||||||
|
static int getMoreData() {
|
||||||
|
System.out.println("begin to start compute");
|
||||||
|
try {
|
||||||
|
Thread.sleep(2000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
System.out.println("end to start compute. passed " + (System.currentTimeMillis() - t) / 1000 + " seconds");
|
||||||
|
return 1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
CompletableFuture<Integer> future = CompletableFuture.supplyAsync(TestCompletableFuture::getMoreData);
|
||||||
|
Future<Integer> f = future.whenComplete((v, e) -> {
|
||||||
|
System.out.println("the result is " + v);
|
||||||
|
e.printStackTrace();
|
||||||
|
});
|
||||||
|
// System.out.println(f.get());
|
||||||
|
|
||||||
|
System.out.println("wait for result.....");
|
||||||
|
|
||||||
|
|
||||||
|
CompletableFuture<Void> f1 = future.thenAccept((x) -> System.out.println("thenAccept " + x));
|
||||||
|
// System.out.println(f1.get());
|
||||||
|
|
||||||
|
|
||||||
|
CompletableFuture<Void> f2 = future.thenAcceptBoth(CompletableFuture.completedFuture(5), (x, y) -> System.out.println("thenAcceptBoth " + x * y));
|
||||||
|
// System.out.println(f2.get());
|
||||||
|
|
||||||
|
Random rand = new Random();
|
||||||
|
CompletableFuture<Integer> future2 = CompletableFuture.supplyAsync(() -> {
|
||||||
|
try {
|
||||||
|
Thread.sleep(1000 + rand.nextInt(1000));
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return 200;
|
||||||
|
});
|
||||||
|
CompletableFuture<String> f3 = future.applyToEither(future2, Object::toString);
|
||||||
|
System.out.println("applyToEither " + f3.get());
|
||||||
|
|
||||||
|
|
||||||
|
CompletableFuture<String> future3 = CompletableFuture.supplyAsync(() -> {
|
||||||
|
try {
|
||||||
|
Thread.sleep(1000 + rand.nextInt(1000));
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return "abc";
|
||||||
|
});
|
||||||
|
CompletableFuture<Void> f4 = CompletableFuture.allOf(future, future2, future3);
|
||||||
|
// CompletableFuture<Object> f4 = CompletableFuture.anyOf(future, future2, future3);
|
||||||
|
// System.out.println("anyOf " + f4.get());
|
||||||
|
|
||||||
|
System.in.read();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -32,7 +32,7 @@ import java.util.concurrent.CountDownLatch;
|
|||||||
public class TestCountDownLatch {
|
public class TestCountDownLatch {
|
||||||
private static final int N = 10;
|
private static final int N = 10;
|
||||||
|
|
||||||
private static final Map<String, Object> cache = new ConcurrentHashMap<String, Object>();
|
private static final Map<String, Object> cache = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
public static void main(String[] args) throws InterruptedException {
|
public static void main(String[] args) throws InterruptedException {
|
||||||
CountDownLatch doneSignal = new CountDownLatch(N);
|
CountDownLatch doneSignal = new CountDownLatch(N);
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.github.ehlxr.thread;
|
package io.github.ehlxr.test;
|
||||||
|
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
@ -22,7 +22,7 @@
|
|||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.github.ehlxr.thread;
|
package io.github.ehlxr.test;
|
||||||
|
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
@ -22,7 +22,7 @@
|
|||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.github.ehlxr;
|
package io.github.ehlxr.test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by ehlxr on 2018/1/16.
|
* Created by ehlxr on 2018/1/16.
|
@ -1,58 +0,0 @@
|
|||||||
/*
|
|
||||||
* The MIT License (MIT)
|
|
||||||
*
|
|
||||||
* Copyright © 2020 xrv <xrg@live.com>
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.github.ehlxr.testminisite;
|
|
||||||
|
|
||||||
import io.github.ehlxr.utils.HttpClientUtil;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class TestMinisite {
|
|
||||||
public static String URL = "http://127.0.0.1:8080/dsp-minisite/Audi2016Q2/getProvinces";
|
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
|
||||||
Map<String, String> params = new HashMap<>();
|
|
||||||
params.put("project", "1");
|
|
||||||
params.put("bid","1");
|
|
||||||
params.put("mapid","1");
|
|
||||||
params.put("name","1");
|
|
||||||
params.put("gender","1");
|
|
||||||
params.put("tel","1");
|
|
||||||
params.put("favoriteModel","1");
|
|
||||||
params.put("province","1");
|
|
||||||
params.put("city","1");
|
|
||||||
params.put("dealerName","1");
|
|
||||||
params.put("dealerCode","1");
|
|
||||||
params.put("scheduledTime","1");
|
|
||||||
params.put("budget","1");
|
|
||||||
|
|
||||||
params.put("provinceName","北京");
|
|
||||||
params.put("cityName","北京");
|
|
||||||
|
|
||||||
// System.out.println(HttpClientUtil.sendPostParam(URL, params));
|
|
||||||
System.out.println(HttpClientUtil.sendGet(URL));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,164 +0,0 @@
|
|||||||
/*
|
|
||||||
* The MIT License (MIT)
|
|
||||||
*
|
|
||||||
* Copyright © 2020 xrv <xrg@live.com>
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.github.ehlxr.testopen;
|
|
||||||
|
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
|
||||||
|
|
||||||
import java.security.MessageDigest;
|
|
||||||
import java.security.NoSuchAlgorithmException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 签名工具类
|
|
||||||
*/
|
|
||||||
public class SignatureUtil {
|
|
||||||
|
|
||||||
|
|
||||||
private static final char[] hexArray = "0123456789ABCDEF".toCharArray();
|
|
||||||
|
|
||||||
private static final String encryptionAlgorithm = "SHA-1";
|
|
||||||
|
|
||||||
public static String bytesToHexString(byte[] bytes) {
|
|
||||||
char[] hexChars = new char[bytes.length * 2];
|
|
||||||
for (int j = 0; j < bytes.length; j++) {
|
|
||||||
int v = bytes[j] & 0xFF;
|
|
||||||
hexChars[j * 2] = hexArray[v >>> 4];
|
|
||||||
hexChars[j * 2 + 1] = hexArray[v & 0x0F];
|
|
||||||
}
|
|
||||||
return new String(hexChars);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static byte[] hexStringToBytes(String s) {
|
|
||||||
int len = s.length();
|
|
||||||
byte[] data = new byte[len / 2];
|
|
||||||
for (int i = 0; i < len; i += 2) {
|
|
||||||
data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) + Character.digit(s.charAt(i + 1), 16));
|
|
||||||
}
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 使用指定算法生成消息摘要,默认是md5
|
|
||||||
*
|
|
||||||
* @param strSrc
|
|
||||||
* , a string will be encrypted; <br/>
|
|
||||||
* @param encName
|
|
||||||
* , the algorithm name will be used, dafault to "MD5"; <br/>
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static String digest(String strSrc, String encName) {
|
|
||||||
MessageDigest md = null;
|
|
||||||
String strDes = null;
|
|
||||||
byte[] bt = strSrc.getBytes();
|
|
||||||
try {
|
|
||||||
if (encName == null || encName.equals("")) {
|
|
||||||
encName = "MD5";
|
|
||||||
}
|
|
||||||
md = MessageDigest.getInstance(encName);
|
|
||||||
md.update(bt);
|
|
||||||
strDes = bytesToHexString(md.digest()); // to HexString
|
|
||||||
} catch (NoSuchAlgorithmException e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return strDes;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据appid、token、lol以及时间戳来生成签名
|
|
||||||
*
|
|
||||||
* @param appid
|
|
||||||
* @param token
|
|
||||||
* @param lol
|
|
||||||
* @param millis
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static String generateSignature(String appid, String token, String lol, long millis) {
|
|
||||||
String timestamp = String.valueOf(millis);
|
|
||||||
String signature = null;
|
|
||||||
if (StringUtils.isNotBlank(token) && StringUtils.isNotBlank(timestamp) && StringUtils.isNotBlank(appid)) {
|
|
||||||
List<String> srcList = new ArrayList<String>();
|
|
||||||
srcList.add(timestamp);
|
|
||||||
srcList.add(appid);
|
|
||||||
srcList.add(token);
|
|
||||||
srcList.add(lol);
|
|
||||||
// 按照字典序逆序拼接参数
|
|
||||||
Collections.sort(srcList);
|
|
||||||
Collections.reverse(srcList);
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
for (int i = 0; i < srcList.size(); i++) {
|
|
||||||
sb.append(srcList.get(i));
|
|
||||||
}
|
|
||||||
signature = digest(sb.toString(), encryptionAlgorithm);
|
|
||||||
srcList.clear();
|
|
||||||
srcList = null;
|
|
||||||
}
|
|
||||||
return signature;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 验证签名: <br/>
|
|
||||||
* 1.根据appid获取该渠道的token;<br/>
|
|
||||||
* 2.根据appid、token、lol以及时间戳计算一次签名;<br/>
|
|
||||||
* 3.比较传过来的签名以及计算出的签名是否一致;
|
|
||||||
*
|
|
||||||
* @param signature
|
|
||||||
* @param appid
|
|
||||||
* @param lol
|
|
||||||
* @param millis
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static boolean isValid(String signature, String appid,String token, String lol, long millis) {
|
|
||||||
String calculatedSignature = generateSignature(appid, token, lol, millis);
|
|
||||||
return StringUtils.equals(calculatedSignature, signature);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
String xmlString = "<root><name>test</name><name>test</name><name>test</name><name>test</name><name>test</name><name>test</name><name>test</name><name>test</name><name>test</name><name>test</name><name>test</name><name>test</name><name>test</name><name>test</name><name>test</name><name>test</name><name>test</name><name>test</name><name>test</name><name>test</name><name>test</name><name>test</name><name>test</name><name>test</name><name>test</name><name>test</name><name>test</name><name>test</name><name>test</name></root>";
|
|
||||||
System.out.println(xmlString.getBytes().length);
|
|
||||||
|
|
||||||
//消息
|
|
||||||
String digest = SignatureUtil.digest(xmlString, "MD5");
|
|
||||||
System.out.println("----" + digest);
|
|
||||||
System.out.println(digest.getBytes().length);
|
|
||||||
|
|
||||||
|
|
||||||
String appid = "canairport001";
|
|
||||||
String token = "111ddff";
|
|
||||||
long millis = System.currentTimeMillis();
|
|
||||||
|
|
||||||
//生成签名
|
|
||||||
String signature = SignatureUtil.generateSignature(appid, token, digest, millis);
|
|
||||||
|
|
||||||
System.out.println(signature);
|
|
||||||
|
|
||||||
//验证签名
|
|
||||||
boolean isValid = SignatureUtil.isValid(signature, appid,token, digest, millis);
|
|
||||||
System.out.println(isValid);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,297 +0,0 @@
|
|||||||
/*
|
|
||||||
* The MIT License (MIT)
|
|
||||||
*
|
|
||||||
* Copyright © 2020 xrv <xrg@live.com>
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.github.ehlxr.testopen;
|
|
||||||
|
|
||||||
import io.github.ehlxr.utils.AESTool;
|
|
||||||
import io.github.ehlxr.utils.Base64;
|
|
||||||
import io.github.ehlxr.utils.HttpClientUtil;
|
|
||||||
import net.sf.json.JSONArray;
|
|
||||||
import net.sf.json.JSONObject;
|
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class TestOpenPuton {
|
|
||||||
private static final String URL = "http://127.0.0.1:8080/dsp-open/pxene/dsp.do";
|
|
||||||
private static final String key = "adjdjfjfjfjdkdkd";//
|
|
||||||
private static final String appid = "t123456";// 用户
|
|
||||||
private static final String token = "cst123456";// 令牌
|
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
|
||||||
|
|
||||||
// String sendPostParam = HttpClientUtil.sendPostParam(URL, getPostParam("setAdxProp"));// 获得数据并且发送请求
|
|
||||||
// String data = getData(sendPostParam);
|
|
||||||
// System.out.println(JSONObject.fromObject(data));
|
|
||||||
|
|
||||||
|
|
||||||
JSONObject json = new JSONObject();
|
|
||||||
json.put("param", "中午");
|
|
||||||
String str = "{\"order_info\":{\"put_time\":[],\"cost_type\":1,\"order_budget\":{\"budget_all\":100.0},\"cost_single\":100.0,\"type\":1,\"order_id\":14575,\"landing_page\":\"www.baidu.com\",\"order_name\":\"tony-test-31\",\"brand_en\":null,\"plat\":1,\"end_time\":\"2016-05-03\",\"creative_group\":[{\"group_name\":\"test_五一\",\"plat\":1,\"ratio\":\"-\",\"group_id\":405,\"click_code\":null,\"impression_code\":null,\"landing_page\":\"www.baidu.com\"}],\"buy_type\":1,\"order_freq\":{\"imp_day_req\":5,\"click_total_freq\":5,\"imp_total_req\":10,\"click_day_freq\":1},\"ad_owner\":{\"owner_qualification\":[],\"owner_name\":\"ABI\",\"organization_code\":null,\"owner_id\":107,\"owner_category\":\"食品饮料>健康饮料,运动饮料,功能性饮料\",\"website_url\":\"http://sedrin.reloadbuzz.com/food2/xueJin/index.php/home/user/index\"},\"start_time\":\"2016-05-03\",\"order_goal\":{\"order_total_show\":1},\"brand_zh\":\"Sedrin\",\"industry\":\"食品饮料>健康饮料,运动饮料,功能性饮料\",\"note\":\"媒体类型定向:\\nnull\\n\\n关键词定向:\\n123\\n\\n广告素材轮播:\\n平均\\n\\n备注:\\n备注1(资源设置):\\n321\\n\\n\\n\"}}";
|
|
||||||
|
|
||||||
System.out.println(HttpClientUtil.sendPostJSONData(URL, str));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getData(String encryptString) throws Exception {
|
|
||||||
byte[] decode = Base64.decode(encryptString.getBytes());
|
|
||||||
String aString = new String(decode, StandardCharsets.UTF_8);
|
|
||||||
String decrypt = AESTool.decrypt(aString, key);
|
|
||||||
return decrypt;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Map<String, String> getPostParam(String content) throws Exception {
|
|
||||||
Map<String, String> postParam = new HashMap<String, String>();
|
|
||||||
content = getContent(content);
|
|
||||||
|
|
||||||
// 业务数据
|
|
||||||
long millis = System.currentTimeMillis();// 时间戳j
|
|
||||||
content = AESTool.encrypt(content, key);// 使用aes加密
|
|
||||||
String lol = SignatureUtil.digest(content, "MD5");// 摘要
|
|
||||||
String signature = SignatureUtil.generateSignature(appid, token, lol, millis);// 签名
|
|
||||||
|
|
||||||
// 准备提交数据
|
|
||||||
postParam.put("appid", appid);
|
|
||||||
postParam.put("content", content);
|
|
||||||
postParam.put("lol", lol);
|
|
||||||
postParam.put("signature", signature);
|
|
||||||
postParam.put("millis", millis + "");
|
|
||||||
|
|
||||||
return postParam;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 在这里写请求数据
|
|
||||||
public static String getContent(String contentName) {
|
|
||||||
JSONObject content = new JSONObject();
|
|
||||||
JSONObject param = new JSONObject();
|
|
||||||
content.put("servicename", "putonServiceCall");
|
|
||||||
|
|
||||||
switch (contentName) {
|
|
||||||
case "putOnByCreative":
|
|
||||||
param.put("campaignid", "26861f62-5cd7-4073-9186-676f8f5d7b24");
|
|
||||||
param.put("groupid", "022ea1a5-3f21-40dd-9c24-c0edfa82bfda");
|
|
||||||
param.put("adxid", "1fed4171-9925-4834-aa7b-9b4d3a58841b");
|
|
||||||
|
|
||||||
JSONArray mapIds = new JSONArray();
|
|
||||||
mapIds.add("28f13909-dbbe-42e4-b9fd-edd97a31d6ce");
|
|
||||||
mapIds.add("8b7b1b4a-eb3a-4be0-809b-b497c58a14f6");
|
|
||||||
mapIds.add("b7f39e0c-3025-4fa3-8e83-ef1f492fe358");
|
|
||||||
param.put("mapids", mapIds);
|
|
||||||
|
|
||||||
content.put("funcname", "putOnByCreative");
|
|
||||||
content.put("methodparam", param);
|
|
||||||
break;
|
|
||||||
case "pauseByCreative":
|
|
||||||
param.put("groupid", "022ea1a5-3f21-40dd-9c24-c0edfa82bfda");
|
|
||||||
param.put("adxid", "1fed4171-9925-4834-aa7b-9b4d3a58841b");
|
|
||||||
|
|
||||||
mapIds = new JSONArray();
|
|
||||||
mapIds.add("28f13909-dbbe-42e4-b9fd-edd97a31d6ce");
|
|
||||||
mapIds.add("8b7b1b4a-eb3a-4be0-809b-b497c58a14f6");
|
|
||||||
mapIds.add("b7f39e0c-3025-4fa3-8e83-ef1f492fe358");
|
|
||||||
param.put("mapids", mapIds);
|
|
||||||
|
|
||||||
content.put("funcname", "pauseByCreative");
|
|
||||||
content.put("methodparam", param);
|
|
||||||
break;
|
|
||||||
case "putOnByAdx":
|
|
||||||
param.put("campaignid", "26861f62-5cd7-4073-9186-676f8f5d7b24");
|
|
||||||
|
|
||||||
JSONArray groupAdxs = new JSONArray();
|
|
||||||
JSONObject groupAdx = new JSONObject();
|
|
||||||
groupAdx.put("groupid", "022ea1a5-3f21-40dd-9c24-c0edfa82bfda");
|
|
||||||
groupAdx.put("adxid", "1fed4171-9925-4834-aa7b-9b4d3a58841b");
|
|
||||||
groupAdxs.add(groupAdx);
|
|
||||||
groupAdx = new JSONObject();
|
|
||||||
groupAdx.put("groupid", "022ea1a5-3f21-40dd-9c24-c0edfa82bfda");
|
|
||||||
groupAdx.put("adxid", "6246ae47-d24b-4afa-88ba-57417ccab6aa");
|
|
||||||
groupAdxs.add(groupAdx);
|
|
||||||
groupAdx = new JSONObject();
|
|
||||||
groupAdx.put("groupid", "022ea1a5-3f21-40dd-9c24-c0edfa82bfda");
|
|
||||||
groupAdx.put("adxid", "ce579246-e707-4cb9-b982-88cad7944b92");
|
|
||||||
groupAdxs.add(groupAdx);
|
|
||||||
|
|
||||||
param.put("groupadxs", groupAdxs);
|
|
||||||
|
|
||||||
content.put("funcname", "putOnByAdx");
|
|
||||||
content.put("methodparam", param);
|
|
||||||
break;
|
|
||||||
case "pauseByAdx":
|
|
||||||
groupAdxs = new JSONArray();
|
|
||||||
groupAdx = new JSONObject();
|
|
||||||
groupAdx.put("groupid", "022ea1a5-3f21-40dd-9c24-c0edfa82bfda");
|
|
||||||
groupAdx.put("adxid", "1fed4171-9925-4834-aa7b-9b4d3a58841b");
|
|
||||||
groupAdxs.add(groupAdx);
|
|
||||||
groupAdx = new JSONObject();
|
|
||||||
groupAdx.put("groupid", "022ea1a5-3f21-40dd-9c24-c0edfa82bfda");
|
|
||||||
groupAdx.put("adxid", "6246ae47-d24b-4afa-88ba-57417ccab6aa");
|
|
||||||
groupAdxs.add(groupAdx);
|
|
||||||
groupAdx = new JSONObject();
|
|
||||||
groupAdx.put("groupid", "022ea1a5-3f21-40dd-9c24-c0edfa82bfda");
|
|
||||||
groupAdx.put("adxid", "ce579246-e707-4cb9-b982-88cad7944b92");
|
|
||||||
groupAdxs.add(groupAdx);
|
|
||||||
|
|
||||||
param.put("groupadxs", groupAdxs);
|
|
||||||
|
|
||||||
content.put("funcname", "pauseByAdx");
|
|
||||||
content.put("methodparam", param);
|
|
||||||
break;
|
|
||||||
case "putOnByGroup":
|
|
||||||
param.put("campaignid", "26861f62-5cd7-4073-9186-676f8f5d7b24");
|
|
||||||
|
|
||||||
JSONArray groupids = new JSONArray();
|
|
||||||
groupids.add("022ea1a5-3f21-40dd-9c24-c0edfa82bfda");
|
|
||||||
param.put("groupids", groupids);
|
|
||||||
|
|
||||||
content.put("funcname", "putOnByGroup");
|
|
||||||
content.put("methodparam", param);
|
|
||||||
break;
|
|
||||||
case "pauseByGroup":
|
|
||||||
groupids = new JSONArray();
|
|
||||||
groupids.add("022ea1a5-3f21-40dd-9c24-c0edfa82bfda");
|
|
||||||
param.put("groupids", groupids);
|
|
||||||
|
|
||||||
content.put("funcname", "pauseByGroup");
|
|
||||||
content.put("methodparam", param);
|
|
||||||
break;
|
|
||||||
case "putOnByCampaign":
|
|
||||||
JSONArray campaignids = new JSONArray();
|
|
||||||
campaignids.add("26861f62-5cd7-4073-9186-676f8f5d7b24");
|
|
||||||
param.put("campaignids", campaignids);
|
|
||||||
|
|
||||||
content.put("funcname", "putOnByCampaign");
|
|
||||||
content.put("methodparam", param);
|
|
||||||
break;
|
|
||||||
case "pauseByCampaign":
|
|
||||||
campaignids = new JSONArray();
|
|
||||||
campaignids.add("26861f62-5cd7-4073-9186-676f8f5d7b24");
|
|
||||||
param.put("campaignids", campaignids);
|
|
||||||
|
|
||||||
content.put("funcname", "pauseByCampaign");
|
|
||||||
content.put("methodparam", param);
|
|
||||||
break;
|
|
||||||
case "setAdxProp":
|
|
||||||
JSONArray propdatas = new JSONArray();
|
|
||||||
JSONObject propdata = new JSONObject();
|
|
||||||
JSONObject adxprop = new JSONObject();
|
|
||||||
JSONArray adxprops = new JSONArray();
|
|
||||||
|
|
||||||
adxprop.put("adxid", "1fed4171-9925-4834-aa7b-9b4d3a58841b");
|
|
||||||
adxprop.put("prop", 20);
|
|
||||||
adxprops.add(adxprop);
|
|
||||||
|
|
||||||
adxprop = new JSONObject();
|
|
||||||
adxprop.put("adxid", "6246ae47-d24b-4afa-88ba-57417ccab6aa");
|
|
||||||
adxprop.put("prop", 15.5);
|
|
||||||
adxprops.add(adxprop);
|
|
||||||
|
|
||||||
adxprop = new JSONObject();
|
|
||||||
adxprop.put("adxid", "ce579246-e707-4cb9-b982-88cad7944b92");
|
|
||||||
adxprop.put("prop", 26.5);
|
|
||||||
adxprops.add(adxprop);
|
|
||||||
|
|
||||||
propdata.put("groupid", "022ea1a5-3f21-40dd-9c24-c0edfa82bfda");
|
|
||||||
propdata.put("adxprops", adxprops);
|
|
||||||
|
|
||||||
propdatas.add(propdata);
|
|
||||||
|
|
||||||
param.put("propdatas", propdatas);
|
|
||||||
content.put("funcname", "setAdxProp");
|
|
||||||
content.put("methodparam", param);
|
|
||||||
break;
|
|
||||||
case "setCreateivePrice":
|
|
||||||
JSONArray createiveprices = new JSONArray();
|
|
||||||
|
|
||||||
JSONObject createiveprice = new JSONObject();
|
|
||||||
createiveprice.put("mapid", "28f13909-dbbe-42e4-b9fd-edd97a31d6ce");
|
|
||||||
createiveprice.put("price", 10);
|
|
||||||
createiveprices.add(createiveprice);
|
|
||||||
|
|
||||||
createiveprice = new JSONObject();
|
|
||||||
createiveprice.put("mapid", "8b7b1b4a-eb3a-4be0-809b-b497c58a14f6");
|
|
||||||
createiveprice.put("price", 6);
|
|
||||||
createiveprices.add(createiveprice);
|
|
||||||
|
|
||||||
createiveprice = new JSONObject();
|
|
||||||
createiveprice.put("mapid", "b7f39e0c-3025-4fa3-8e83-ef1f492fe358");
|
|
||||||
createiveprice.put("price", 8);
|
|
||||||
createiveprices.add(createiveprice);
|
|
||||||
|
|
||||||
param.put("groupid", "022ea1a5-3f21-40dd-9c24-c0edfa82bfda");
|
|
||||||
param.put("adxid", "1fed4171-9925-4834-aa7b-9b4d3a58841b");
|
|
||||||
param.put("createiveprices", createiveprices);
|
|
||||||
|
|
||||||
content.put("funcname", "setCreateivePrice");
|
|
||||||
content.put("methodparam", param);
|
|
||||||
break;
|
|
||||||
case "getKpiByCampaignIds":
|
|
||||||
campaignids = new JSONArray();
|
|
||||||
campaignids.add("26861f62-5cd7-4073-9186-676f8f5d7b24");
|
|
||||||
|
|
||||||
param.put("campaignids", campaignids);
|
|
||||||
|
|
||||||
content.put("funcname", "getKpiByCampaignIds");
|
|
||||||
content.put("methodparam", param);
|
|
||||||
break;
|
|
||||||
case "getKpiByGroupIds":
|
|
||||||
groupids = new JSONArray();
|
|
||||||
groupids.add("022ea1a5-3f21-40dd-9c24-c0edfa82bfda");
|
|
||||||
|
|
||||||
param.put("groupids", groupids);
|
|
||||||
|
|
||||||
content.put("funcname", "getKpiByGroupIds");
|
|
||||||
content.put("methodparam", param);
|
|
||||||
break;
|
|
||||||
case "getKpiByAdxIds":
|
|
||||||
JSONArray adxids = new JSONArray();
|
|
||||||
adxids.add("1fed4171-9925-4834-aa7b-9b4d3a58841b");
|
|
||||||
adxids.add("6246ae47-d24b-4afa-88ba-57417ccab6aa");
|
|
||||||
adxids.add("ce579246-e707-4cb9-b982-88cad7944b92");
|
|
||||||
|
|
||||||
param.put("groupid", "022ea1a5-3f21-40dd-9c24-c0edfa82bfda");
|
|
||||||
param.put("adxids", adxids);
|
|
||||||
|
|
||||||
content.put("funcname", "getKpiByAdxIds");
|
|
||||||
content.put("methodparam", param);
|
|
||||||
break;
|
|
||||||
case "getKpiByMapIds":
|
|
||||||
JSONArray mapids = new JSONArray();
|
|
||||||
mapids.add("28f13909-dbbe-42e4-b9fd-edd97a31d6ce");
|
|
||||||
mapids.add("8b7b1b4a-eb3a-4be0-809b-b497c58a14f6");
|
|
||||||
mapids.add("b7f39e0c-3025-4fa3-8e83-ef1f492fe358");
|
|
||||||
|
|
||||||
param.put("groupid", "022ea1a5-3f21-40dd-9c24-c0edfa82bfda");
|
|
||||||
param.put("adxid", "1fed4171-9925-4834-aa7b-9b4d3a58841b");
|
|
||||||
param.put("mapids", mapids);
|
|
||||||
|
|
||||||
content.put("funcname", "getKpiByMapIds");
|
|
||||||
content.put("methodparam", param);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
System.out.println(content.toString());
|
|
||||||
return content.toString();
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user