From 70c123c2cf45f4f003ff4f730f7cdd56bf17068d Mon Sep 17 00:00:00 2001 From: 苗权威 <1160292058@qq.com> Date: Sat, 27 Jul 2019 18:48:57 +0800 Subject: [PATCH] 7.27 --- .idea/compiler.xml | 2 ++ .idea/encodings.xml | 1 + .idea/misc.xml | 1 + .idea/workspace.xml | 821 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- xiaoai/src/main/java/ai/qiwu/mi/xiaoai/controller/XiaoAiController.java | 10 ++++++---- xiaoai/src/main/java/ai/qiwu/mi/xiaoai/service/XiaoAiService.java | 1 - xiaodu/pom.xml | 20 ++++++++++++++++++++ xiaodu/src/main/java/ai/qiwu/baidu/xiaodu/common/Constants.java | 25 +++++++++++++++++++++++-- xiaodu/src/main/java/ai/qiwu/baidu/xiaodu/common/OkHttp3Utils.java | 45 +++++++++++++++++++++++++++++++++++++++++++++ xiaodu/src/main/java/ai/qiwu/baidu/xiaodu/common/ProductError.java | 37 +++++++++++++++++++++++++++++++++++++ xiaodu/src/main/java/ai/qiwu/baidu/xiaodu/common/Utils.java | 27 +++++++++++++++++++++++++-- xiaodu/src/main/java/ai/qiwu/baidu/xiaodu/controller/Oauth2Controller.java | 22 ++++++++++++++++++++-- xiaodu/src/main/java/ai/qiwu/baidu/xiaodu/controller/ProductController.java | 246 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ xiaodu/src/main/java/ai/qiwu/baidu/xiaodu/controller/XiaoDuController.java | 22 ++++++++-------------- xiaodu/src/main/java/ai/qiwu/baidu/xiaodu/pojo/product/CustomProductPrompts.java | 2 ++ xiaodu/src/main/java/ai/qiwu/baidu/xiaodu/pojo/product/Pricing.java | 2 ++ xiaodu/src/main/java/ai/qiwu/baidu/xiaodu/pojo/product/Product.java | 2 ++ xiaodu/src/main/java/ai/qiwu/baidu/xiaodu/pojo/product/ProductTokenHolder.java | 17 +++++++++++++++++ xiaodu/src/main/java/ai/qiwu/baidu/xiaodu/pojo/product/PublishingInformation.java | 2 ++ xiaodu/src/main/java/ai/qiwu/baidu/xiaodu/pojo/product/UpdateRequestBody.java | 19 +++++++++++++++++++ xiaodu/src/main/java/ai/qiwu/baidu/xiaodu/pojo/product/response/ProductIdRequest.java | 16 ++++++++++++++++ xiaodu/src/main/java/ai/qiwu/baidu/xiaodu/pojo/product/response/PubDelUpdResponse.java | 17 +++++++++++++++++ xiaodu/src/main/java/ai/qiwu/baidu/xiaodu/pojo/product/response/PublishRequestBody.java | 14 -------------- xiaodu/src/main/java/ai/qiwu/baidu/xiaodu/pojo/product/response/QueryProductDataItem.java | 20 ++++++++++++++++++++ xiaodu/src/main/java/ai/qiwu/baidu/xiaodu/pojo/product/response/QueryProductResponse.java | 18 ++++++++++++++++++ xiaodu/src/main/java/ai/qiwu/baidu/xiaodu/pojo/product/response/SkillProduct.java | 35 +++++++++++++++++++++++++++++++++++ xiaodu/src/main/java/ai/qiwu/baidu/xiaodu/service/LoadBySMS.java | 1 + xiaodu/src/main/java/ai/qiwu/baidu/xiaodu/service/MultipartResolver.java | 21 +++++++++++++++++++++ xiaodu/src/main/java/ai/qiwu/baidu/xiaodu/service/ResponseEncapsulation.java | 123 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------- xiaodu/src/main/java/ai/qiwu/baidu/xiaodu/service/productManager/ProductManager.java | 250 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------------------------------------------------------------------------------------- xiaodu/src/main/resources/application.properties | 4 ++++ xiaodu/src/main/resources/static/picture/big.jpg | Bin 62543 -> 0 bytes xiaodu/src/main/resources/static/picture/small.jpg | Bin 7812 -> 0 bytes xiaodu/src/main/resources/templates/AboutProductResult.html | 10 ++++++++++ xiaodu/src/main/resources/templates/Facade.html | 15 +++++++++++++++ xiaodu/src/main/resources/templates/Oauth2_load.html | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------ xiaodu/src/main/resources/templates/Product.html | 258 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ xiaodu/src/main/resources/templates/QueryProduct.html | 125 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ xiaodu/src/main/resources/templates/UpdateProduct.html | 217 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ xiaodu/src/main/resources/templates/home_load.html | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ xiaoduhome/.gitignore | 31 +++++++++++++++++++++++++++++++ xiaoduhome/.mvn/wrapper/MavenWrapperDownloader.java | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ xiaoduhome/.mvn/wrapper/maven-wrapper.jar | Bin 0 -> 48337 bytes xiaoduhome/.mvn/wrapper/maven-wrapper.properties | 1 + xiaoduhome/mvnw | 286 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ xiaoduhome/mvnw.cmd | 161 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ xiaoduhome/pom.xml | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/XiaoduhomeApplication.java | 13 +++++++++++++ xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/common/Constants.java | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/common/OkHttp3Utils.java | 149 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/common/Utils.java | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/controller/XiaoDuHomeController.java | 28 ++++++++++++++++++++++++++++ xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/pojo/GetUserInfoByToken.java | 19 +++++++++++++++++++ xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/pojo/QiWuRequest.java | 18 ++++++++++++++++++ xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/pojo/QiWuResponse.java | 13 +++++++++++++ xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/service/RequestTerminal.java | 33 +++++++++++++++++++++++++++++++++ xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/service/ResponseEncapsulation.java | 320 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ xiaoduhome/src/main/resources/application.properties | 1 + xiaoduhome/src/test/java/ai/qiwu/com/xiaoduhome/XiaoduhomeApplicationTests.java | 16 ++++++++++++++++ 59 files changed, 3463 insertions(+), 682 deletions(-) create mode 100644 xiaodu/src/main/java/ai/qiwu/baidu/xiaodu/common/ProductError.java create mode 100644 xiaodu/src/main/java/ai/qiwu/baidu/xiaodu/controller/ProductController.java create mode 100644 xiaodu/src/main/java/ai/qiwu/baidu/xiaodu/pojo/product/ProductTokenHolder.java create mode 100644 xiaodu/src/main/java/ai/qiwu/baidu/xiaodu/pojo/product/UpdateRequestBody.java create mode 100644 xiaodu/src/main/java/ai/qiwu/baidu/xiaodu/pojo/product/response/ProductIdRequest.java create mode 100644 xiaodu/src/main/java/ai/qiwu/baidu/xiaodu/pojo/product/response/PubDelUpdResponse.java delete mode 100644 xiaodu/src/main/java/ai/qiwu/baidu/xiaodu/pojo/product/response/PublishRequestBody.java create mode 100644 xiaodu/src/main/java/ai/qiwu/baidu/xiaodu/pojo/product/response/QueryProductDataItem.java create mode 100644 xiaodu/src/main/java/ai/qiwu/baidu/xiaodu/pojo/product/response/QueryProductResponse.java create mode 100644 xiaodu/src/main/java/ai/qiwu/baidu/xiaodu/pojo/product/response/SkillProduct.java create mode 100644 xiaodu/src/main/java/ai/qiwu/baidu/xiaodu/service/MultipartResolver.java delete mode 100644 xiaodu/src/main/resources/static/picture/big.jpg delete mode 100644 xiaodu/src/main/resources/static/picture/small.jpg create mode 100644 xiaodu/src/main/resources/templates/AboutProductResult.html create mode 100644 xiaodu/src/main/resources/templates/Facade.html create mode 100644 xiaodu/src/main/resources/templates/Product.html create mode 100644 xiaodu/src/main/resources/templates/QueryProduct.html create mode 100644 xiaodu/src/main/resources/templates/UpdateProduct.html create mode 100644 xiaodu/src/main/resources/templates/home_load.html create mode 100644 xiaoduhome/.gitignore create mode 100644 xiaoduhome/.mvn/wrapper/MavenWrapperDownloader.java create mode 100644 xiaoduhome/.mvn/wrapper/maven-wrapper.jar create mode 100644 xiaoduhome/.mvn/wrapper/maven-wrapper.properties create mode 100755 xiaoduhome/mvnw create mode 100644 xiaoduhome/mvnw.cmd create mode 100644 xiaoduhome/pom.xml create mode 100644 xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/XiaoduhomeApplication.java create mode 100644 xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/common/Constants.java create mode 100644 xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/common/OkHttp3Utils.java create mode 100644 xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/common/Utils.java create mode 100644 xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/controller/XiaoDuHomeController.java create mode 100644 xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/pojo/GetUserInfoByToken.java create mode 100644 xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/pojo/QiWuRequest.java create mode 100644 xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/pojo/QiWuResponse.java create mode 100644 xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/service/RequestTerminal.java create mode 100644 xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/service/ResponseEncapsulation.java create mode 100644 xiaoduhome/src/main/resources/application.properties create mode 100644 xiaoduhome/src/test/java/ai/qiwu/com/xiaoduhome/XiaoduhomeApplicationTests.java diff --git a/.idea/compiler.xml b/.idea/compiler.xml index c8ba906..1236775 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -14,6 +14,7 @@ + @@ -33,6 +34,7 @@ + diff --git a/.idea/encodings.xml b/.idea/encodings.xml index c55775d..b9f8147 100644 --- a/.idea/encodings.xml +++ b/.idea/encodings.xml @@ -9,6 +9,7 @@ + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index c591921..4e91bec 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -24,6 +24,7 @@ diff --git a/.idea/workspace.xml b/.idea/workspace.xml index c75ad1b..46911f1 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -3,23 +3,29 @@ - + + - - - - + + - + + - + + - + + + + + + @@ -34,6 +40,7 @@ + + + + + + + + + + - + - - - - - - - - - + + - - + + - - - - - + + - + - - + + - - - - - - + + + + + + - + - + + + + + + + + + + + + + @@ -120,21 +138,22 @@ response - logger OPENID_TIMESTAMP msgId + logger + StreamResponse - log OPENID_CACHE + log @@ -143,57 +162,57 @@ @@ -211,20 +230,6 @@ - - - - - - - - - - - - - - @@ -240,10 +245,10 @@ - @@ -253,7 +258,6 @@ - @@ -270,110 +274,13 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -381,7 +288,6 @@ - @@ -390,7 +296,6 @@ - @@ -400,7 +305,6 @@ - @@ -430,16 +334,6 @@ - - - - - - - - - - @@ -457,21 +351,13 @@ - - - - - - - - - + + + + + + \ No newline at end of file diff --git a/xiaodu/src/main/resources/templates/Oauth2_load.html b/xiaodu/src/main/resources/templates/Oauth2_load.html index 9751e4b..0def3b1 100644 --- a/xiaodu/src/main/resources/templates/Oauth2_load.html +++ b/xiaodu/src/main/resources/templates/Oauth2_load.html @@ -4,20 +4,10 @@ 登录 + - -

手机号: -

-

填写验证码:

- +
+ +
+

获取验证码

+ + +
+
+

请输入验证码

+ + +
+
\ No newline at end of file diff --git a/xiaodu/src/main/resources/templates/Product.html b/xiaodu/src/main/resources/templates/Product.html new file mode 100644 index 0000000..e968a07 --- /dev/null +++ b/xiaodu/src/main/resources/templates/Product.html @@ -0,0 +1,258 @@ + + + + + 上传商品 + + + +

+

+ +
+

商品所属技能

+
+ +

版本,默认1.0

+
+ +

调用商品的名称,不允许重复,最多21个字

+
+ +

ENTITLEMENT:商品不可重复购买 CONSUMABLE:商品可重复购买

+
+ +

商品信息中的商品名称,最多85个字

+
+ +

商品概述,最多66个字

+
+ +

商品详细说明,最多333个字

+
+ +

原始价格,单位元,不能为0

+
+ +

实际价格,单位元,不能为0

+
+ +

商品图片,请先填写作品名,图片类型.注:作品名要唯一

+ +
+

商品小图,尺寸 128*128

+
+ +
+
+ + +

商品大图,尺寸 512*512

+ + +
+
+ + +

分类(可不填),最多10个字

+
+ +

购买提示(可不填),最多3个子项,逗号分隔,每个子项长度不超过15字

+
+
+
+ +

关键词(可不填),最多5个子项,逗号分隔,每个子项长度不超过10字

+
+
+
+
+
+ +

商品是否可以购买-PURCHASABLE, NOT_PURCHASABLE(可不填,默认可以)

+
+ +

购买时的语音播报(可不填),最多66个字

+
+ +

对话流购买卡片上展示提示(可不填)

+
+ + +
+ + \ No newline at end of file diff --git a/xiaodu/src/main/resources/templates/QueryProduct.html b/xiaodu/src/main/resources/templates/QueryProduct.html new file mode 100644 index 0000000..3d8f66e --- /dev/null +++ b/xiaodu/src/main/resources/templates/QueryProduct.html @@ -0,0 +1,125 @@ + + + + + 查询 + + + + +
+
+
+ + +
+
+ + +
+
+
+
+
+

+
+
+

技能id:

+

商品id:

+

商品信息中的商品名称:

+

商品类型:

+ 商品小图 + 商品大图
+ 原始价格: + 实际价格: + 发布阶段: + 商品是否可以购买: +

bot中调用商品的名称:

+

商品概述:

+ 商品详细说明: +

分类:

+

购买提示:

+

关键词:

+

购买时的语音播报:

+

对话流购买卡片上展示提示:

+
+
+
+ + +
+
+ + \ No newline at end of file diff --git a/xiaodu/src/main/resources/templates/UpdateProduct.html b/xiaodu/src/main/resources/templates/UpdateProduct.html new file mode 100644 index 0000000..77456d1 --- /dev/null +++ b/xiaodu/src/main/resources/templates/UpdateProduct.html @@ -0,0 +1,217 @@ + + + + + 上传商品 + + + +

商品所属技能

+
+ +

版本,默认1.0

+
+ +

调用商品的名称,不允许重复,最多21个字

+
+ +

ENTITLEMENT:商品不可重复购买 CONSUMABLE:商品可重复购买

+
+ +

商品信息中的商品名称,最多85个字

+
+ +

商品概述,最多66个字

+
+ +

商品详细说明,最多333个字

+
+ +

原始价格,单位元,不能为0

+
+ +

实际价格,单位元,不能为0

+
+ +

商品图片,请先填写作品名,图片类型.注:作品名要唯一

+ +
+

商品小图,尺寸 128*128

+
+
+
+ + +

商品大图,尺寸 512*512

+ +
+
+ + +

分类(可不填),最多10个字

+
+ +

购买提示(可不填),最多3个子项,逗号分隔,每个子项长度不超过15字

+
+
+
+ +

关键词(可不填),最多5个子项,逗号分隔,每个子项长度不超过10字

+
+
+
+
+
+ +

商品是否可以购买-PURCHASABLE, NOT_PURCHASABLE(可不填,默认可以)

+
+ +

购买时的语音播报(可不填),最多66个字

+
+ +

对话流购买卡片上展示提示(可不填)

+
+ + + + \ No newline at end of file diff --git a/xiaodu/src/main/resources/templates/home_load.html b/xiaodu/src/main/resources/templates/home_load.html new file mode 100644 index 0000000..c288706 --- /dev/null +++ b/xiaodu/src/main/resources/templates/home_load.html @@ -0,0 +1,114 @@ + + + + + 登录 + + + + +
+ +
+

获取验证码

+ + +
+
+

请输入验证码

+ + +
+
+ + \ No newline at end of file diff --git a/xiaoduhome/.gitignore b/xiaoduhome/.gitignore new file mode 100644 index 0000000..a2a3040 --- /dev/null +++ b/xiaoduhome/.gitignore @@ -0,0 +1,31 @@ +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/** +!**/src/test/** + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ + +### VS Code ### +.vscode/ diff --git a/xiaoduhome/.mvn/wrapper/MavenWrapperDownloader.java b/xiaoduhome/.mvn/wrapper/MavenWrapperDownloader.java new file mode 100644 index 0000000..7f91a56 --- /dev/null +++ b/xiaoduhome/.mvn/wrapper/MavenWrapperDownloader.java @@ -0,0 +1,114 @@ +/* +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + https://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +*/ + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.net.URL; +import java.nio.channels.Channels; +import java.nio.channels.ReadableByteChannel; +import java.util.Properties; + +public class MavenWrapperDownloader { + + /** + * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. + */ + private static final String DEFAULT_DOWNLOAD_URL = + "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar"; + + /** + * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to + * use instead of the default one. + */ + private static final String MAVEN_WRAPPER_PROPERTIES_PATH = + ".mvn/wrapper/maven-wrapper.properties"; + + /** + * Path where the maven-wrapper.jar will be saved to. + */ + private static final String MAVEN_WRAPPER_JAR_PATH = + ".mvn/wrapper/maven-wrapper.jar"; + + /** + * Name of the property which should be used to override the default download url for the wrapper. + */ + private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; + + public static void main(String args[]) { + System.out.println("- Downloader started"); + File baseDirectory = new File(args[0]); + System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); + + // If the maven-wrapper.properties exists, read it and check if it contains a custom + // wrapperUrl parameter. + File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); + String url = DEFAULT_DOWNLOAD_URL; + if (mavenWrapperPropertyFile.exists()) { + FileInputStream mavenWrapperPropertyFileInputStream = null; + try { + mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); + Properties mavenWrapperProperties = new Properties(); + mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); + url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); + } catch (IOException e) { + System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); + } finally { + try { + if (mavenWrapperPropertyFileInputStream != null) { + mavenWrapperPropertyFileInputStream.close(); + } + } catch (IOException e) { + // Ignore ... + } + } + } + System.out.println("- Downloading from: : " + url); + + File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); + if (!outputFile.getParentFile().exists()) { + if (!outputFile.getParentFile().mkdirs()) { + System.out.println( + "- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'"); + } + } + System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); + try { + downloadFileFromURL(url, outputFile); + System.out.println("Done"); + System.exit(0); + } catch (Throwable e) { + System.out.println("- Error downloading"); + e.printStackTrace(); + System.exit(1); + } + } + + private static void downloadFileFromURL(String urlString, File destination) throws Exception { + URL website = new URL(urlString); + ReadableByteChannel rbc; + rbc = Channels.newChannel(website.openStream()); + FileOutputStream fos = new FileOutputStream(destination); + fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); + fos.close(); + rbc.close(); + } + +} diff --git a/xiaoduhome/.mvn/wrapper/maven-wrapper.jar b/xiaoduhome/.mvn/wrapper/maven-wrapper.jar new file mode 100644 index 0000000..01e6799 Binary files /dev/null and b/xiaoduhome/.mvn/wrapper/maven-wrapper.jar differ diff --git a/xiaoduhome/.mvn/wrapper/maven-wrapper.properties b/xiaoduhome/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000..cd0d451 --- /dev/null +++ b/xiaoduhome/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1 @@ +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.0/apache-maven-3.6.0-bin.zip diff --git a/xiaoduhome/mvnw b/xiaoduhome/mvnw new file mode 100755 index 0000000..8b9da3b --- /dev/null +++ b/xiaoduhome/mvnw @@ -0,0 +1,286 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Maven2 Start Up Batch script +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# M2_HOME - location of maven2's installed home dir +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ] ; then + + if [ -f /etc/mavenrc ] ; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ] ; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false; +darwin=false; +mingw=false +case "`uname`" in + CYGWIN*) cygwin=true ;; + MINGW*) mingw=true;; + Darwin*) darwin=true + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + export JAVA_HOME="`/usr/libexec/java_home`" + else + export JAVA_HOME="/Library/Java/Home" + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=`java-config --jre-home` + fi +fi + +if [ -z "$M2_HOME" ] ; then + ## resolve links - $0 may be a link to maven's home + PRG="$0" + + # need this for relative symlinks + while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG="`dirname "$PRG"`/$link" + fi + done + + saveddir=`pwd` + + M2_HOME=`dirname "$PRG"`/.. + + # make it fully qualified + M2_HOME=`cd "$M2_HOME" && pwd` + + cd "$saveddir" + # echo Using m2 at $M2_HOME +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --unix "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --unix "$CLASSPATH"` +fi + +# For Mingw, ensure paths are in UNIX format before anything is touched +if $mingw ; then + [ -n "$M2_HOME" ] && + M2_HOME="`(cd "$M2_HOME"; pwd)`" + [ -n "$JAVA_HOME" ] && + JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" + # TODO classpath? +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="`which javac`" + if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=`which readlink` + if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then + if $darwin ; then + javaHome="`dirname \"$javaExecutable\"`" + javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" + else + javaExecutable="`readlink -f \"$javaExecutable\"`" + fi + javaHome="`dirname \"$javaExecutable\"`" + javaHome=`expr "$javaHome" : '\(.*\)/bin'` + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ] ; then + if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD="`which java`" + fi +fi + +if [ ! -x "$JAVACMD" ] ; then + echo "Error: JAVA_HOME is not defined correctly." >&2 + echo " We cannot execute $JAVACMD" >&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ] ; then + echo "Warning: JAVA_HOME environment variable is not set." +fi + +CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + + if [ -z "$1" ] + then + echo "Path not specified to find_maven_basedir" + return 1 + fi + + basedir="$1" + wdir="$1" + while [ "$wdir" != '/' ] ; do + if [ -d "$wdir"/.mvn ] ; then + basedir=$wdir + break + fi + # workaround for JBEAP-8937 (on Solaris 10/Sparc) + if [ -d "${wdir}" ]; then + wdir=`cd "$wdir/.."; pwd` + fi + # end of workaround + done + echo "${basedir}" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + echo "$(tr -s '\n' ' ' < "$1")" + fi +} + +BASE_DIR=`find_maven_basedir "$(pwd)"` +if [ -z "$BASE_DIR" ]; then + exit 1; +fi + +########################################################################################## +# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +# This allows using the maven wrapper in projects that prohibit checking in binary data. +########################################################################################## +if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found .mvn/wrapper/maven-wrapper.jar" + fi +else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." + fi + jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar" + while IFS="=" read key value; do + case "$key" in (wrapperUrl) jarUrl="$value"; break ;; + esac + done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" + if [ "$MVNW_VERBOSE" = true ]; then + echo "Downloading from: $jarUrl" + fi + wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" + + if command -v wget > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found wget ... using wget" + fi + wget "$jarUrl" -O "$wrapperJarPath" + elif command -v curl > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found curl ... using curl" + fi + curl -o "$wrapperJarPath" "$jarUrl" + else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Falling back to using Java to download" + fi + javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" + if [ -e "$javaClass" ]; then + if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Compiling MavenWrapperDownloader.java ..." + fi + # Compiling the Java class + ("$JAVA_HOME/bin/javac" "$javaClass") + fi + if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + # Running the downloader + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Running MavenWrapperDownloader.java ..." + fi + ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") + fi + fi + fi +fi +########################################################################################## +# End of extension +########################################################################################## + +export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} +if [ "$MVNW_VERBOSE" = true ]; then + echo $MAVEN_PROJECTBASEDIR +fi +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --path --windows "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --windows "$CLASSPATH"` + [ -n "$MAVEN_PROJECTBASEDIR" ] && + MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` +fi + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +exec "$JAVACMD" \ + $MAVEN_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/xiaoduhome/mvnw.cmd b/xiaoduhome/mvnw.cmd new file mode 100644 index 0000000..fef5a8f --- /dev/null +++ b/xiaoduhome/mvnw.cmd @@ -0,0 +1,161 @@ +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM https://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Maven2 Start Up Batch script +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM M2_HOME - location of maven2's installed home dir +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM set title of command window +title %0 +@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" +if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar" +FOR /F "tokens=1,2 delims==" %%A IN (%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties) DO ( + IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B +) + +@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +@REM This allows using the maven wrapper in projects that prohibit checking in binary data. +if exist %WRAPPER_JAR% ( + echo Found %WRAPPER_JAR% +) else ( + echo Couldn't find %WRAPPER_JAR%, downloading it ... + echo Downloading from: %DOWNLOAD_URL% + powershell -Command "(New-Object Net.WebClient).DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')" + echo Finished downloading %WRAPPER_JAR% +) +@REM End of extension + +%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" +if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%" == "on" pause + +if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% + +exit /B %ERROR_CODE% diff --git a/xiaoduhome/pom.xml b/xiaoduhome/pom.xml new file mode 100644 index 0000000..6f44619 --- /dev/null +++ b/xiaoduhome/pom.xml @@ -0,0 +1,81 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.1.6.RELEASE + + + ai.qiwu.com + xiaoduhome + 0.0.1-SNAPSHOT + xiaoduhome + Demo project for Spring Boot + + + 1.8 + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-test + test + + + com.baidu.dueros + bot-sdk + + + org.slf4j + slf4j-log4j12 + + + 1.2.0 + + + com.alibaba + fastjson + 1.2.58 + + + org.projectlombok + lombok + 1.18.8 + provided + + + com.squareup.okhttp3 + okhttp + 4.0.0 + + + com.squareup.okhttp3 + okhttp + 4.0.0 + + + com.alibaba + fastjson + 1.2.58 + + + + + xiaoduhome + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/XiaoduhomeApplication.java b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/XiaoduhomeApplication.java new file mode 100644 index 0000000..3872858 --- /dev/null +++ b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/XiaoduhomeApplication.java @@ -0,0 +1,13 @@ +package ai.qiwu.com.xiaoduhome; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class XiaoduhomeApplication { + + public static void main(String[] args) { + SpringApplication.run(XiaoduhomeApplication.class, args); + } + +} diff --git a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/common/Constants.java b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/common/Constants.java new file mode 100644 index 0000000..cd419bf --- /dev/null +++ b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/common/Constants.java @@ -0,0 +1,81 @@ +package ai.qiwu.com.xiaoduhome.common; + +/** + * @author 苗权威 + * @dateTime 19-6-29 下午3:06 + */ +public interface Constants { + + String QI_WU_INTERFACE = "http://aliyun-hz1.chewrobot.com:8070/api/chat"; + String SERVICE_NAME = "BAIDU"; + String PRIVATE_KEY = "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBANMWIYduiQZt0B7s" + + "IZ6PW15gpcO7Yn+9ZbaMSHwzJqNeDAZzh6HXF7r0ZpQcw3XEWKPAPWyuJ5eqZf46" + + "W/NyJQkcddWrA/5OvcZw1uAmzTt8sWz1zokt2e6v6SucvvHoPxLGjfTKWh6Qr+2x" + + "K/5wmdOOpikL/ruH2ZviYjto2cBPAgMBAAECgYBuQCLnD8618uk/HWo53PqGAsjR" + + "wK+jtJLJk9/QLw9BSL/TJshyuVuFpF1ngtZ8Tj9V1/S9LQE08CUxcd3Q+49njgEq" + + "R60FKDjwCe8G9El5jIYIU0RTnd84I8B0RKWBO8ShZ29qWEVXOExPZc1fMlq4UgBr" + + "Xkfsh/E1cTfphYyS8QJBAOuX1c11XOSeDVo5KyxM26K2Kiekjm1cLIXJR54hetRN" + + "diCHqd5WyolKJzxFuUMEsq+sAfgd7KsrorO5hwY42lUCQQDlXt9TiIWGMt3oVEIf" + + "ulJQmURhkQ+Z9EC2wHnFrE3UhkCNyX3TOwTzV8bzC+Vr2hAobbhXTCr8tLGm0Yxk" + + "f1wTAkEAqbQtplosF+Jh6+PSXY7fh02BAB1hGxWSXKyokhe7ysIhnT0b97S9IDfy" + + "G1B+KvBvZmuY34luub4s7RlvUeQSIQJANaq7Cip5Q2sHbOK6Df5kYCNcUo/EXLs/" + + "oQLr+wpTs5Qt6n7oh9HZWK6DCD8SUOfWu/7gENzrefE1V9jTxnfeLQJBANKf4QfA" + + "CvwfHTyEgphcWrWDzB7bEqUDWiEjfO8sf+lwj9I0yU6fO/+aUtwU9xwkij1PscUF" + + "9AWUhbas+LG9mds="; + Integer GET_PRODUCT_TOKEN_FAIL_STATUS = 10086; + + interface SKILL_SECURITY { + String REDIRECT_URI = "https://xiaodu.baidu.com/saiya/auth/3428011e7f55ec4c10b2da1b00a1675b"; + String REDIRECT_URI_TEST = "https://xiaodu-dbp.baidu.com/saiya/auth/3428011e7f55ec4c10b2da1b00a1675b"; + String CLIENT_ID = "aiqiwucom"; + String CLIENT_SECRET = "miaoquanwei"; + } + + interface WelcomeWord { + String WELCOME = "在这里你就是主角,开始你的星辰大海吧,请说推荐作品"; + String BEGIN_NO_RESPONSE = "咋还没开始就停住了,我们这里可有很多好玩的作品哦"; + } + + interface EndMsg { + String BYE_BYE = "我们的作品库在不断的扩充,下次会有更大的惊喜哦"; + String CAN_NOT_UNDERSTAND = "用户无输入或多次输入无法理解"; + String USER_SAY_CANCEL = "用户直接说退出"; + } + + interface ErrorMsg { + String SORRY_UNCATCH = "我好意思我没听清,请再说一遍吧"; + String INTERNAL_ERROR = "其他DuerOS系统错误"; + String INVALID_RESPONSE = "技能返回了无效的响应,可能技能响应数据量超过24KB,或是技能在request的dialogState为COMPLETED时仍然发送Dialog.Delegate指令等"; + String DEVICE_COMMUNICATION_ERROR = "DuerOS与端通信异常"; + + String INTERFACE_ERROR = "终端接口请求出错"; + String HTTP_CONNECTION_CLOSE_FAILED = "与终端的链接关闭错误"; + } + + interface ManageProduct { + String BAIDU_COOKIE = "BAIDUID=5A90207BBC953C38E8FEAB3B064D8E7B:FG=1;BDUSS=Vota2FuQldVUmc3LVl0aTJ5NDVLOENKR1BLekxVMngzOHZBc1EtUW5sR25rRjlkSUFBQUFBJCQAAAAAAAAAAAEAAACty2MsUmVhY2hsb3ZlAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAKcDOF2nAzhdU"; + String GET_TOKEN = "https://xiaodu.baidu.com/dbppay/skill-pay/product/token"; + String CREATE_PRODUCT = "https://xiaodu.baidu.com/dbppay/skill-pay/product/inskillproducts"; + String UPDATE_PRODUCT = "https://xiaodu.baidu.com/dbppay/skill-pay/product/inskillproducts"; + String DELETE_PRODUCT = "https://xiaodu.baidu.com/dbppay/skill-pay/product/inskillproducts"; + String QUERY_PRODUCT = "https://xiaodu.baidu.com/dbppay/skill-pay/product/inskillproducts"; + String PUBLISH_PRODUCT = "https://xiaodu.baidu.com/dbppay/skill-pay/product/publish"; + String GET_ALL_PRODUCT_SITUATION = "https://xiaodu.baidu.com/dbppay/skill-pay/saiya/v1/skills/inskillproducts"; + } + + interface XIAOWU_API { + String BASIC_PREFIX = "Basic "; + String BEARER = "Bearer "; + String CAPTCHA_SMS = "https://account-center-test.chewrobot.com/api/captcha/sms"; + String SDK_TOKEN = "https://account-center-test.chewrobot.com/api/sdk/token"; + String GET_USER_INFO_BY_TOKEN ="https://account-center-test.chewrobot.com/api/sdk/user/info"; + } + + interface BAI_DU { + String RETURN_BAIDU_TOKEN = "https://openapi.baidu.com/oauth/2.0/token"; + String BAIDU_TOKEN = "https://openapi.baidu.com/oauth/2.0/token?grant_type=authorization_code&client_id=dSG525LMr887uLlfAyK1C1ag&client_secret=1azuXoKHMSWT5MVNNkZ4C5mED23qySZh&redirect_uri=https%3A%2F%2Fwww.miaoshop.top%2Fxiaodu%2Fbaidu%2Fcode&code="; + String BAIDU_AUTHORIZE = "https://openapi.baidu.com/oauth/2.0/authorize?response_type=code&client_id=dSG525LMr887uLlfAyK1C1ag&redirect_uri=https%3A%2F%2Fwww.miaoshop.top%2Fxiaodu%2Fbaidu%2Fcode&confirm_login=1&state=mqw"; + } + + +} diff --git a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/common/OkHttp3Utils.java b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/common/OkHttp3Utils.java new file mode 100644 index 0000000..944cdba --- /dev/null +++ b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/common/OkHttp3Utils.java @@ -0,0 +1,149 @@ +package ai.qiwu.com.xiaoduhome.common; + +import okhttp3.*; + +import java.io.File; +import java.io.IOException; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +/** + * @author 苗权威 + * @dateTime 19-7-18 上午10:54 + */ +public class OkHttp3Utils { + private static OkHttpClient client = new OkHttpClient(); + + public static String doGet(String url) throws IOException { + return doGet(url, new HashMap<>()); + } + + public static String doGet(String url, Map params) throws IOException { + return doGet(url, params, new HashMap<>()); + } + + public static String doGet(String url, Map params, Map header) throws IOException { + Request.Builder builder = new Request.Builder(); + Request request = builder.url(url).build(); + HttpUrl.Builder urlBuild = request.url().newBuilder(); + Headers.Builder headerBuilder = request.headers().newBuilder(); + + Iterator> headIterator = header.entrySet().iterator(); + headIterator.forEachRemaining(e -> headerBuilder.add(e.getKey(), e.getValue())); + + Iterator> paramsIterator = params.entrySet().iterator(); + paramsIterator.forEachRemaining(e -> urlBuild.addQueryParameter(e.getKey(), e.getValue())); + + builder.url(urlBuild.build()).headers(headerBuilder.build()); + try (Response response = client.newCall(builder.build()).execute()){ + return response.body().string(); + } + } + + public static String doPost(String url, Map params) throws IOException { + return doPost(url, new HashMap<>(), params,null); + } + + public static String doPost(String url, Map params, Map headers) throws IOException { + return doPost(url, headers, params, null); + } + + public static String doPost(String url, File file) throws IOException { + return doPost(url , new HashMap<>(), new HashMap<>(), file); + } + + public static String doPostJsonStr(String url, Map headers, String requestJsonStr) throws IOException { + Request.Builder builder = new Request.Builder(); + Request request = builder.url(url).build(); + + Headers.Builder headBuilder = request.headers().newBuilder(); + + Iterator> headIterator = headers.entrySet().iterator(); + headIterator.forEachRemaining(e -> headBuilder.add(e.getKey(), e.getValue())); + + builder.headers(headBuilder.build()).post(RequestBody.create(MediaType.parse("application/json; charset=utf-8"), requestJsonStr)); + try (Response response = client.newCall(builder.build()).execute()){ + return response.body().string(); + } + } + + public static String doPost(String url, Map headers, Map params, File file) throws IOException { + Request.Builder builder = new Request.Builder(); + Request request = builder.url(url).build(); + + Headers.Builder headBuilder = request.headers().newBuilder(); + + Iterator> headIterator = headers.entrySet().iterator(); + headIterator.forEachRemaining(e -> headBuilder.add(e.getKey(), e.getValue())); + + MultipartBody.Builder requestBuilder = new MultipartBody.Builder(); + Iterator> paramsIterator = params.entrySet().iterator(); + paramsIterator.forEachRemaining(e -> requestBuilder.addFormDataPart(e.getKey(), e.getValue())); + + if (file != null) { + requestBuilder.addFormDataPart("uploadFiles", file.getName(), + RequestBody.create(MediaType.parse("application/octet-stream"), file)); + } + builder.headers(headBuilder.build()).post(requestBuilder.build()); + + try (Response response = client.newCall(builder.build()).execute()){ + return response.body().string(); + } + } + + public static String doPost(String url, Map headers, Map params, + String fileName, byte[] fileByte) throws IOException { + Request.Builder builder = new Request.Builder(); + Request request = builder.url(url).build(); + + Headers.Builder headBuilder = request.headers().newBuilder(); + + Iterator> headIterator = headers.entrySet().iterator(); + headIterator.forEachRemaining(e -> headBuilder.add(e.getKey(), e.getValue())); + + MultipartBody.Builder requestBuilder = new MultipartBody.Builder(); + Iterator> paramsIterator = params.entrySet().iterator(); + paramsIterator.forEachRemaining(e -> requestBuilder.addFormDataPart(e.getKey(), e.getValue())); + + if (fileByte.length > 0) { + requestBuilder.addFormDataPart("uploadFiles", fileName, + RequestBody.create(MediaType.parse("application/octet-stream"), fileByte)); + } + builder.headers(headBuilder.build()).post(requestBuilder.build()); + + try (Response response = client.newCall(builder.build()).execute()){ + return response.body().string(); + } + } + + public static String doPut(String url, Map headers, String jsonStr) throws IOException { + Request.Builder builder = new Request.Builder(); + Request request = builder.url(url).build(); + + Headers.Builder headBuilder = request.headers().newBuilder(); + + Iterator> headIterator = headers.entrySet().iterator(); + headIterator.forEachRemaining(e -> headBuilder.add(e.getKey(), e.getValue())); + + builder.headers(headBuilder.build()).put(RequestBody.create(MediaType.parse("application/json; charset=utf-8"), jsonStr)); + try (Response response = client.newCall(builder.build()).execute()){ + return response.body().string(); + } + } + + public static String doDelete(String url, Map headers, String jsonStr) throws IOException { + Request.Builder builder = new Request.Builder(); + Request request = builder.url(url).build(); + + Headers.Builder headBuilder = request.headers().newBuilder(); + + Iterator> headIterator = headers.entrySet().iterator(); + headIterator.forEachRemaining(e -> headBuilder.add(e.getKey(), e.getValue())); + + builder.headers(headBuilder.build()).delete(RequestBody.create(MediaType.parse("application/json; charset=utf-8"), jsonStr)); + try (Response response = client.newCall(builder.build()).execute()){ + return response.body().string(); + } + } +} diff --git a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/common/Utils.java b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/common/Utils.java new file mode 100644 index 0000000..3c0a6c4 --- /dev/null +++ b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/common/Utils.java @@ -0,0 +1,98 @@ +package ai.qiwu.com.xiaoduhome.common; + +import org.apache.commons.codec.binary.Base64; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; + +import javax.servlet.http.HttpServletRequest; +import java.nio.charset.StandardCharsets; +import java.util.Objects; + +/** + * @author 苗权威 + * @dateTime 19-6-29 下午5:11 + */ +public class Utils { + + /** + * 校验电话号码 + */ + private static final String REGEX_MOBILE = "^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(17[013678])|(18[0,5-9]))\\d{8}$"; + + public static HttpServletRequest getHttpServletRequest() { + return ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder + .getRequestAttributes())).getRequest(); + } + + public static String useIPAsItsID() { + HttpServletRequest request = getHttpServletRequest(); + String ip = request.getHeader("x-forwarded-for"); + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + ip = request.getHeader("Proxy-Client-IP"); + } + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + ip = request.getHeader("WL-Proxy-Client-IP"); + } + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + ip = request.getRemoteAddr(); + } + return ip; + } + + /** + * 验证小度请求登录时发来的信息 + * @param clientId + * @param redirectUri + * @return + */ + public static boolean verifyLoadRequest(String clientId, String redirectUri) { + return Constants.SKILL_SECURITY.CLIENT_ID.equals(clientId) && + (Constants.SKILL_SECURITY.REDIRECT_URI_TEST.equals(redirectUri)|| + Constants.SKILL_SECURITY.REDIRECT_URI.equals(redirectUri)); + } + + /** + * 验证小度请求Token时发来的信息 + * @param clientId + * @param clientSecret + * @param redirectUri + * @return + */ + public static boolean verifyTokenRequest(String clientId, String clientSecret, String redirectUri) { +// log.info("clientID:{},clientSecret:{},redirectUri:{}", clientId, clientSecret, redirectUri); + return Constants.SKILL_SECURITY.CLIENT_ID.equals(clientId) && + (Constants.SKILL_SECURITY.REDIRECT_URI_TEST.equals(redirectUri)|| + Constants.SKILL_SECURITY.REDIRECT_URI.equals(redirectUri)) && + Constants.SKILL_SECURITY.CLIENT_SECRET.equals(clientSecret); + } + + /** + * 校验电话号码 + * @param phoneNumber + * @return + */ + public static boolean verifyPhoneNumber(String phoneNumber) { + return phoneNumber.matches(REGEX_MOBILE); + } + + /** + * Authorization:Basic+空格+base64加密后的电话号码 + * @param phoneNumber + * @return + */ + public static String captchaAuthorization(String phoneNumber) { + return Constants.XIAOWU_API.BASIC_PREFIX + Base64.encodeBase64String(phoneNumber.getBytes()); + } + + /** + * Authorization:Basic+空格+base64加密后的(电话号码:验证码) + * @param phoneNumber + * @param captcha + * @return + */ + public static String tokenAuthorization(String phoneNumber, String captcha) { + String str = phoneNumber + ":" + captcha; + str = Base64.encodeBase64String(str.getBytes(StandardCharsets.UTF_8)); + return Constants.XIAOWU_API.BASIC_PREFIX + str; + } +} diff --git a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/controller/XiaoDuHomeController.java b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/controller/XiaoDuHomeController.java new file mode 100644 index 0000000..70dee28 --- /dev/null +++ b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/controller/XiaoDuHomeController.java @@ -0,0 +1,28 @@ +package ai.qiwu.com.xiaoduhome.controller; + +import ai.qiwu.com.xiaoduhome.common.Utils; +import ai.qiwu.com.xiaoduhome.service.ResponseEncapsulation; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * @author 苗权威 + * @dateTime 19-7-26 下午9:27 + */ +@RestController +@Slf4j +public class XiaoDuHomeController { + @RequestMapping("/xiaoduhome") + public String chat() { + try { + ResponseEncapsulation response = new ResponseEncapsulation(Utils.getHttpServletRequest()); + response.enableVerify(); + //response.disableVerify(); + return response.run(); + } catch (Exception e) { + log.info("出现错误 "+e.toString()); + } + return null; + } +} diff --git a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/pojo/GetUserInfoByToken.java b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/pojo/GetUserInfoByToken.java new file mode 100644 index 0000000..24eeb0b --- /dev/null +++ b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/pojo/GetUserInfoByToken.java @@ -0,0 +1,19 @@ +package ai.qiwu.com.xiaoduhome.pojo; + +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; + +/** + * @author 苗权威 + * @dateTime 19-7-18 下午1:33 + */ +@Getter +@Setter +@ToString +public class GetUserInfoByToken { + private String message; + private String payload; + private Integer retcode; + private Integer status; +} diff --git a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/pojo/QiWuRequest.java b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/pojo/QiWuRequest.java new file mode 100644 index 0000000..bf3662a --- /dev/null +++ b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/pojo/QiWuRequest.java @@ -0,0 +1,18 @@ +package ai.qiwu.com.xiaoduhome.pojo; + +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; + +/** + * @author 苗权威 + * @dateTime 19-7-10 下午2:29 + */ +@Getter +@Setter +@ToString +public class QiWuRequest { + private String user_id; + private String text; + private String access; +} diff --git a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/pojo/QiWuResponse.java b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/pojo/QiWuResponse.java new file mode 100644 index 0000000..2729eba --- /dev/null +++ b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/pojo/QiWuResponse.java @@ -0,0 +1,13 @@ +package ai.qiwu.com.xiaoduhome.pojo; + +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@ToString +public class QiWuResponse { + private String audio; + private String text; +} diff --git a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/service/RequestTerminal.java b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/service/RequestTerminal.java new file mode 100644 index 0000000..5428dc2 --- /dev/null +++ b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/service/RequestTerminal.java @@ -0,0 +1,33 @@ +package ai.qiwu.com.xiaoduhome.service; + +import ai.qiwu.com.xiaoduhome.common.Constants; +import ai.qiwu.com.xiaoduhome.common.OkHttp3Utils; +import ai.qiwu.com.xiaoduhome.pojo.QiWuRequest; +import ai.qiwu.com.xiaoduhome.pojo.QiWuResponse; +import com.alibaba.fastjson.JSON; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.HashMap; + +/** + * @author 苗权威 + * @dateTime 19-6-29 下午3:49 + */ +class RequestTerminal { + + private static final Logger logger = LoggerFactory.getLogger(RequestTerminal.class); + + static QiWuResponse requestTerminate(String userId, String userWord) throws IOException { + QiWuRequest requestPojo = new QiWuRequest(); + requestPojo.setUser_id(userId); + requestPojo.setAccess(Constants.SERVICE_NAME); + requestPojo.setText(userWord); + String requestJsonStr = JSON.toJSONString(requestPojo); + HashMap headers = new HashMap<>(); + headers.put("Content-Type", "application/json;charset=utf-8"); + String resStr = OkHttp3Utils.doPostJsonStr(Constants.QI_WU_INTERFACE, headers, requestJsonStr); + return JSON.parseObject(resStr, QiWuResponse.class); + } +} diff --git a/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/service/ResponseEncapsulation.java b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/service/ResponseEncapsulation.java new file mode 100644 index 0000000..61971ce --- /dev/null +++ b/xiaoduhome/src/main/java/ai/qiwu/com/xiaoduhome/service/ResponseEncapsulation.java @@ -0,0 +1,320 @@ +package ai.qiwu.com.xiaoduhome.service; + +import ai.qiwu.com.xiaoduhome.common.Constants; +import ai.qiwu.com.xiaoduhome.common.Constants.EndMsg; +import ai.qiwu.com.xiaoduhome.common.Constants.WelcomeWord; +import ai.qiwu.com.xiaoduhome.common.Constants.ErrorMsg; +import ai.qiwu.com.xiaoduhome.common.OkHttp3Utils; +import ai.qiwu.com.xiaoduhome.common.Utils; +import ai.qiwu.com.xiaoduhome.pojo.GetUserInfoByToken; +import ai.qiwu.com.xiaoduhome.pojo.QiWuResponse; +import com.alibaba.fastjson.JSON; +import com.baidu.dueros.bot.AudioPlayer; +import com.baidu.dueros.data.request.*; +import com.baidu.dueros.data.request.audioplayer.event.PlaybackFinishedEvent; +import com.baidu.dueros.data.request.audioplayer.event.PlaybackStoppedEvent; +import com.baidu.dueros.data.request.buy.event.BuyEvent; +import com.baidu.dueros.data.request.events.LinkAccountSucceededEvent; +import com.baidu.dueros.data.request.pay.event.ChargeEvent; +import com.baidu.dueros.data.request.pay.event.Payload; +import com.baidu.dueros.data.response.OutputSpeech; +import com.baidu.dueros.data.response.Reprompt; +import com.baidu.dueros.data.response.card.Card; +import com.baidu.dueros.data.response.card.LinkAccountCard; +import com.baidu.dueros.data.response.directive.audioplayer.AudioPlayerDirective; +import com.baidu.dueros.data.response.directive.audioplayer.Play; +import com.baidu.dueros.data.response.directive.display.Hint; +import com.baidu.dueros.data.response.directive.display.RenderTemplate; +import com.baidu.dueros.data.response.directive.display.templates.*; +import com.baidu.dueros.data.response.directive.display.templates.BodyTemplate1.PositionType; +import com.baidu.dueros.data.response.directive.pay.Buy; +import com.baidu.dueros.data.response.directive.pay.Charge; +import com.baidu.dueros.model.Response; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import javax.servlet.http.HttpServletRequest; +import java.io.IOException; +import java.util.*; + +/** + * @author 苗权威 + * @dateTime 19-6-28 下午8:22 + */ +@Slf4j +public class ResponseEncapsulation extends AudioPlayer { + private static final Boolean USE_CHARGE_ORDER = false; + + public ResponseEncapsulation(HttpServletRequest request) throws IOException { + super(request); + String privateKey = "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBANMWIYduiQZt0B7s" + + "IZ6PW15gpcO7Yn+9ZbaMSHwzJqNeDAZzh6HXF7r0ZpQcw3XEWKPAPWyuJ5eqZf46" + + "W/NyJQkcddWrA/5OvcZw1uAmzTt8sWz1zokt2e6v6SucvvHoPxLGjfTKWh6Qr+2x" + + "K/5wmdOOpikL/ruH2ZviYjto2cBPAgMBAAECgYBuQCLnD8618uk/HWo53PqGAsjR" + + "wK+jtJLJk9/QLw9BSL/TJshyuVuFpF1ngtZ8Tj9V1/S9LQE08CUxcd3Q+49njgEq" + + "R60FKDjwCe8G9El5jIYIU0RTnd84I8B0RKWBO8ShZ29qWEVXOExPZc1fMlq4UgBr" + + "Xkfsh/E1cTfphYyS8QJBAOuX1c11XOSeDVo5KyxM26K2Kiekjm1cLIXJR54hetRN" + + "diCHqd5WyolKJzxFuUMEsq+sAfgd7KsrorO5hwY42lUCQQDlXt9TiIWGMt3oVEIf" + + "ulJQmURhkQ+Z9EC2wHnFrE3UhkCNyX3TOwTzV8bzC+Vr2hAobbhXTCr8tLGm0Yxk" + + "f1wTAkEAqbQtplosF+Jh6+PSXY7fh02BAB1hGxWSXKyokhe7ysIhnT0b97S9IDfy" + + "G1B+KvBvZmuY34luub4s7RlvUeQSIQJANaq7Cip5Q2sHbOK6Df5kYCNcUo/EXLs/" + + "oQLr+wpTs5Qt6n7oh9HZWK6DCD8SUOfWu/7gENzrefE1V9jTxnfeLQJBANKf4QfA" + + "CvwfHTyEgphcWrWDzB7bEqUDWiEjfO8sf+lwj9I0yU6fO/+aUtwU9xwkij1PscUF" + + "9AWUhbas+LG9mds="; + //privateKey为私钥内容,0代表你的Bot在DBP平台debug环境,1或者其他整数代表online环境, + // botMonitor对象已经在bot-sdk里初始化,可以直接调用 + //this.botMonitor.setEnvironmentInfo(privateKey, 0); + //this.botMonitor.setMonitorEnabled(true); + } + + @Override + protected Response onChargeEvent(ChargeEvent chargeEvent) { + Payload payload = chargeEvent.getPayload(); + if (payload.getPurchaseResult().equals("SUCCESS")) { + log.info("支付成功,"+payload.getMessage()); + log.info("百度扣款金额:"+chargeEvent.getPayload().getAuthorizationDetails().getCapturedAmount().getAmount()); + log.info("本次交易百度生成的订单ID:"+chargeEvent.getPayload().getBaiduOrderReferenceId()); + log.info("对应支付的订单ID:"+chargeEvent.getPayload().getSellerOrderId()); + return buildErrorResponse("恭喜您支付成功,开始体验吧"); + }else { + log.info("支付发生错误,"+payload.getMessage()); + return buildErrorResponse("哎呀,没有支付成功"); + } + } + + @Override + protected Response onBuyEvent(BuyEvent buyEvent) { + com.baidu.dueros.data.request.buy.event.Payload payload = buyEvent.getPayload(); + String result = payload.getPurchaseResult().getPurchaseResult(); + log.info("此次支付结果:"+result+";msg: "+payload.getMessage()); + if (result.equals("SUCCESS")) { + log.info("支付成功"); + return buildErrorResponse("恭喜您支付成功,开始体验吧"); + } + return buildErrorResponse("哎呀,没有支付成功"); + } + + @Override + protected Response onLinkAccountSucceededEvent(LinkAccountSucceededEvent linkAccountSucceededEvent) { + log.info("登录成功返回信息:{}",linkAccountSucceededEvent); + return buildErrorResponse("您已登录成功"); + } + + @Override + protected Response onInent(IntentRequest intentRequest) { + String userId = getCustomerId(); + String timestamp = this.getRequest().getRequest().getTimestamp(); + Query query = intentRequest.getQuery(); + String userWord = null; + if (query != null) userWord = query.getOriginal(); + if (userWord == null){ + log.info("小度没有传来任何话语"); + return buildErrorResponse(ErrorMsg.SORRY_UNCATCH); + } + + log.info("请求消息:"+this.getStrRequest()); + if (getIntent().getName().equals("buy")) { + String productName = getSlot("sys.wildcard-slot"); + log.info("用户要购买的作品名:"+productName); + String accessToken; + if ((accessToken = getAccessToken()) == null) { + log.info("未登录"); + Card card = new LinkAccountCard(); +// Card card = new TextCard("点击登录", "https://www.miaoshop.top/xiaodu/load?userId="+userId, "跳转链接"); + Response response = buildErrorResponse("请在屏幕或是小度App上完成登录"); + response.setCard(card); + return response; + }else { + if (USE_CHARGE_ORDER) { + int hasUserAlreadyOwned; + try { + hasUserAlreadyOwned = hasUserBuyTheThing(accessToken); + } catch (Exception e) { + log.info("判断用户是否已购买操作出错:"+e.toString()); + return new Response(new OutputSpeech(OutputSpeech.SpeechType.PlainText, "请在说一遍吧")); + } + switch (hasUserAlreadyOwned) { + case 1 : log.info("用户已经购买");// 已购买如何处理 + case 2 : { + log.info("用户需要进行购买"); + String sellerOrderId = "sgaggg"+new Random(47).nextInt(1000)+"aga"+new Random(47).nextInt(765355); + Charge chargeDirective = new Charge("0.01", sellerOrderId, + productName, productName+",这是个非常精彩的故事哦"); + addDirective(chargeDirective); + OutputSpeech outputSpeech = new OutputSpeech(OutputSpeech.SpeechType.PlainText, "请到小度APP上去支付"); + return new Response(outputSpeech); + } + case 3 : return new Response(new OutputSpeech(OutputSpeech.SpeechType.PlainText, "请在说一遍吧")); + case 4 : { + // token失效 + Card card = new LinkAccountCard(); + Response response = buildErrorResponse("请在屏幕或是小度App上完成登录"); + response.setCard(card); + return response; + } + } + }else { + String productId = "190725134159854900"; + Buy buy = new Buy(productId); + addDirective(buy); + OutputSpeech outputSpeech = new OutputSpeech(OutputSpeech.SpeechType.PlainText, "请到小度APP上去支付"); + return new Response(outputSpeech); + } + } + }else { + QiWuResponse data = null; + try { + data = RequestTerminal.requestTerminate(userId, userWord); + } catch (Exception e) { + log.error("请求终端接口出错:{}", e.toString()); + } + if (data == null) { + return buildErrorResponse(ErrorMsg.SORRY_UNCATCH); + } + String audioUrl = data.getAudio(); + String uri = "https://aliyun-hz1.chewrobot.com/xiaodu/image/5b2d0a11/lvzhou/1564033095964d39f.jpg"; + ImageStructure imageStructure = new ImageStructure(uri, 512, 512); + Tag tag = new Tag("PAY", "支付标签"); + imageStructure.addTag(tag); + Tpl1Content tpl1Content = new Tpl1Content(TextStructure.TextType.PlainText,data.getText()); + tpl1Content.setPosition(PositionType.CENTER); + BodyTemplate1 template1 = new BodyTemplate1("互动小说", tpl1Content); + template1.setBackgroundImage(imageStructure); + addDirective(buildPlayDirective(audioUrl, AudioPlayerDirective.PlayBehaviorType.REPLACE_ALL)); + addDirective(new RenderTemplate(template1)); + String hint1 = "说退出就会退出当前作品"; + String hint2 = "开始时说推荐作品会向您推荐更多作品"; + String hint3 = "我们的作品库在不断扩充"; + String hint4 = "希望您玩的开心"; + ArrayList hints = new ArrayList<>(); + hints.add(hint1); + hints.add(hint2); + hints.add(hint3); + hints.add(hint4); + addDirective(new Hint(hints)); + } + return new Response(); + } + + @Override + public Response onLaunch(LaunchRequest launchRequest) { + log.info("请求消息:"+this.getStrRequest()); + //USER_TIMESTAMP.put(getCustomerId(), new Holder()); + OutputSpeech outputSpeech = new OutputSpeech(OutputSpeech.SpeechType.PlainText, WelcomeWord.WELCOME); + Reprompt reprompt = new Reprompt(new OutputSpeech(OutputSpeech.SpeechType.PlainText, WelcomeWord.BEGIN_NO_RESPONSE)); + return new Response(outputSpeech, null, reprompt); + } + + @Override + public Response onSessionEnded(SessionEndedRequest sessionEndedRequest) { + log.info("触发结束事件,"+this.getStrRequest()); + switch (sessionEndedRequest.getReason()) { + case ERROR: dealWithError(sessionEndedRequest); break; + case USER_INITIATED: log.info(EndMsg.USER_SAY_CANCEL); break; + case EXCEEDED_MAX_REPROMPTS: log.info(EndMsg.CAN_NOT_UNDERSTAND);break; + } + // 向终端发送“退出” +// OutputSpeech outputSpeech = new OutputSpeech(OutputSpeech.SpeechType.PlainText, EndMsg.BYE_BYE); +// RequestTerminal.requestTerminate("退出", getCustomerId()); +// return new Response(outputSpeech); + return new Response(); + } + + private void dealWithError(SessionEndedRequest request) { + switch (request.getError().getType()) { + case INTERNAL_ERROR: log.info(ErrorMsg.INTERNAL_ERROR); break; + case INVALID_RESPONSE: log.info(ErrorMsg.INVALID_RESPONSE); break; + case DEVICE_COMMUNICATION_ERROR: log.info(ErrorMsg.DEVICE_COMMUNICATION_ERROR); break; + } + log.info("错误信息 : "+ request.getError().getMessage()); + } + + private Response buildErrorResponse(String errorMsg) { + OutputSpeech outputSpeech = new OutputSpeech(OutputSpeech.SpeechType.PlainText, errorMsg); + return new Response(outputSpeech); + } + + private Play buildPlayDirective(String audioUrl, AudioPlayerDirective.PlayBehaviorType type) { + return new Play(type, audioUrl, 0); + + } + + /** + * 音频播放结束,开麦 + * + * expectSpeech + * 在会话进行过程中,技能是否需要用户进行对话响应。该字段可选,并且仅在shouldEndSession为false时有效。 + * true:表示技能需要用户进行对话响应,设备端上打开麦克风聆听用户的语音。 + * false:表示技能不需要用户进行对话响应,设备端上关闭麦克风。 + * + * shouldEndSession字段和expectSpeech字段同时为false,技能还在会话中,但是不需要用户进行回复, + * 设备端会关闭麦克风,此时可以返回AudioPlayer.Play指令。 + * @param playbackFinishedEvent + * @return + */ + @Override + protected Response onPlaybackFinishedEvent(PlaybackFinishedEvent playbackFinishedEvent) { + log.info("音频播放完毕,开麦"); + this.waitAnswer(); + this.setExpectSpeech(true); + return new Response(); + } + + @Override + protected Response onPlaybackStoppedEvent(PlaybackStoppedEvent playbackStoppedEvent) { + log.info("音频播放停止"); + this.waitAnswer(); + return new Response(); + } + + @Override + protected Response onDefaultEvent() { + log.info("未拦截的事件类型:"+getEventType(this.getStrRequest())); + this.waitAnswer(); + return new Response(); + } + + private String getCustomerId() { + String userId; + try { + userId = getUserId(); + } catch (NullPointerException e) { + userId = Utils.useIPAsItsID(); + } + return userId; + } + + private String getEventType(String requestStr) { + int typeIndex = requestStr.lastIndexOf("type"); + int comma = requestStr.indexOf(',', typeIndex); + return requestStr.substring(typeIndex, comma); + } + + private String getAsrRawResult(String requestStr) { + int asrIndex = requestStr.lastIndexOf("asrRawResult"); + int asrWordBegin = requestStr.indexOf(':', asrIndex)+2; + int asrWordEnd = requestStr.indexOf('"',asrWordBegin); + return requestStr.substring(asrWordBegin, asrWordEnd); + } + + private Integer hasUserBuyTheThing(String accessToken) throws IOException { + Map headers = new HashMap<>(); + headers.put("App-Channel-Id", "JIAOYOUTIANXIA"); + headers.put("Authorization", Constants.XIAOWU_API.BEARER+accessToken); + String responseStr = OkHttp3Utils.doGet(Constants.XIAOWU_API.GET_USER_INFO_BY_TOKEN, new HashMap<>(), headers); + GetUserInfoByToken userInfo = JSON.parseObject(responseStr, GetUserInfoByToken.class); + if (userInfo.getRetcode() == 0) { + log.info("获取用户信息成功,"+userInfo); + // 1: buy; 2: not buy + return 1; + }else { + log.warn("获取用户信息失败:"+userInfo); + // 若token失效刷新Token操作 + // 3: 404,获取用户信息失败,提醒用户再说一遍 + // 4: 401,403..让用户重新登录 + Integer status = userInfo.getStatus(); + if (status == 404) return 3; + else return 4; + } + } +} diff --git a/xiaoduhome/src/main/resources/application.properties b/xiaoduhome/src/main/resources/application.properties new file mode 100644 index 0000000..f8992a5 --- /dev/null +++ b/xiaoduhome/src/main/resources/application.properties @@ -0,0 +1 @@ +server.port=8188 diff --git a/xiaoduhome/src/test/java/ai/qiwu/com/xiaoduhome/XiaoduhomeApplicationTests.java b/xiaoduhome/src/test/java/ai/qiwu/com/xiaoduhome/XiaoduhomeApplicationTests.java new file mode 100644 index 0000000..b4ef341 --- /dev/null +++ b/xiaoduhome/src/test/java/ai/qiwu/com/xiaoduhome/XiaoduhomeApplicationTests.java @@ -0,0 +1,16 @@ +package ai.qiwu.com.xiaoduhome; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class XiaoduhomeApplicationTests { + + @Test + public void contextLoads() { + } + +} -- libgit2 0.27.1