|
@@ -1,6 +1,7 @@
|
|
|
package com.iotechn.unimall.admin.api.shop.impl;
|
|
|
|
|
|
import java.io.*;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
|
|
@@ -33,6 +34,7 @@ import org.apache.http.client.entity.UrlEncodedFormEntity;
|
|
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
|
|
import org.apache.http.client.methods.HttpGet;
|
|
|
import org.apache.http.client.methods.HttpPost;
|
|
|
+import org.apache.http.entity.StringEntity;
|
|
|
import org.apache.http.impl.client.BasicCookieStore;
|
|
|
import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
import org.apache.http.impl.client.HttpClientBuilder;
|
|
@@ -335,8 +337,7 @@ public class ShopOrderServiceImpl implements IShopOrderService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public ShopOrder callPhone(String mobile) throws Exception {
|
|
|
-
|
|
|
+ public ShopOrder callPhone(String mobile,String bookName) throws Exception {
|
|
|
ApiTokenV1.ApiAuthTokenV1Builder builder = new ApiTokenV1.ApiAuthTokenV1Builder();
|
|
|
// 必填参数 ak,sk,uri,host,http method, 过期时间
|
|
|
builder.ak("346da55bb3c248ea84e39b5913939f05"); // ak
|
|
@@ -345,18 +346,15 @@ public class ShopOrderServiceImpl implements IShopOrderService {
|
|
|
builder.host("aicc.bce.baidu.com"); // host
|
|
|
builder.httpMethod("POST"); // http method
|
|
|
builder.expireInSeconds(1800); // 过期时间
|
|
|
-
|
|
|
// 以下是非必须参数
|
|
|
// 参与生成token的请求头, 此处若使用了x-bce-date,则调用外呼api接口时,请求头内必需带上x-bce-date
|
|
|
-// HashMap<String, String> headerMap = new HashMap<String, String>();
|
|
|
-// headerMap.put("x-bce-date", "2022-06-17T08:40:14Z");
|
|
|
-// builder.httpHeaderMap(headerMap);
|
|
|
- builder.httpHeader("Content-Type", "application/json");
|
|
|
- builder.httpHeader("Authorization", builder.build().getToken());
|
|
|
- // url里?带的参数,如/api/v1/robot/list?robotName=test, 没有?参数可以不调用此方法
|
|
|
- builder.queryStr("robotId=b304c245-ec71-40ef-b7b8-c94e6874e8ed&mobile="+mobile+"&secretType=2");
|
|
|
+ HashMap<String, String> headerMap = new HashMap<String, String>();
|
|
|
+ headerMap.put("x-bce-date", "2022-06-23T16:52:14Z");
|
|
|
+ builder.httpHeaderMap(headerMap);
|
|
|
+ // builder.httpHeader("Content-Type", "application/json");
|
|
|
|
|
|
- System.out.println(builder.build().getToken());
|
|
|
+ // url里?带的参数,如/api/v1/robot/list?robotName=test, 没有?参数可以不调用此方法
|
|
|
+ // builder.queryStr("robotName=test&pn=1");
|
|
|
String token = builder.build().getToken();
|
|
|
System.out.println("token=" + token);
|
|
|
// 登陆 Url
|
|
@@ -364,25 +362,22 @@ public class ShopOrderServiceImpl implements IShopOrderService {
|
|
|
CloseableHttpClient httpClient = HttpClients.createDefault();
|
|
|
// 模拟登陆,按实际服务器端要求选用 Post 或 Get 请求方式
|
|
|
HttpPost httpPost = new HttpPost(loginUrl);
|
|
|
- // 装填参数
|
|
|
- List<BasicNameValuePair> nvps = new ArrayList<BasicNameValuePair>();
|
|
|
- nvps.add(new BasicNameValuePair("robotId", "b304c245-ec71-40ef-b7b8-c94e6874e8ed"));
|
|
|
- nvps.add(new BasicNameValuePair("mobile", mobile));
|
|
|
- nvps.add(new BasicNameValuePair("secretType", "2"));
|
|
|
- // 设置参数到请求对象中
|
|
|
- httpPost.setEntity(new UrlEncodedFormEntity(nvps, "UTF-8"));
|
|
|
-
|
|
|
+ JSONObject params = new JSONObject();
|
|
|
+ JSONObject param1 = new JSONObject();
|
|
|
+ param1.put("bookname", bookName);
|
|
|
+ params.put("robotId", "73ec968b-b587-4249-a391-a475439df725");
|
|
|
+ params.put("mobile", mobile);
|
|
|
+ params.put("secretType", "2");
|
|
|
+ params.put("dialogVar", param1);
|
|
|
+ httpPost.setEntity(new StringEntity(params.toString(), StandardCharsets.UTF_8));
|
|
|
// 设置header信息
|
|
|
// 指定报文头【Content-type】、【User-Agent】
|
|
|
httpPost.setHeader("Content-type", "application/json");
|
|
|
httpPost.setHeader("Authorization", token);
|
|
|
- httpPost.setHeader("x-bce-date", "2022-06-17T08:40:14Z");
|
|
|
-
|
|
|
+ httpPost.setHeader("x-bce-date", "2022-06-23T16:52:14Z");
|
|
|
// 执行请求操作,并拿到结果(同步阻塞)
|
|
|
CloseableHttpResponse response = httpClient.execute(httpPost);
|
|
|
try {
|
|
|
- if (response.getStatusLine().getStatusCode() == 302) {
|
|
|
- }
|
|
|
System.out.println(EntityUtils.toString(response.getEntity(), "UTF-8"));
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|