| | |
| | | import com.ruoyi.common.core.domain.model.LoginUser; |
| | | import com.ruoyi.common.utils.AliSmsUtil; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.VoiceNotifyMain; |
| | | import com.ruoyi.framework.web.service.TokenService; |
| | | import com.ruoyi.system.dto.AddBuyerCompanyInfoDto; |
| | | import com.ruoyi.system.dto.AddScheduleDto; |
| | |
| | | messageService.addMessage("买家申请了交易", company.getUserId(), orderId,1); |
| | | |
| | | TbUser user = userService.getById(company.getUserId()); |
| | | AliSmsUtil.sendSuccessMessageSeller(user.getPhone()); |
| | | // AliSmsUtil.sendSuccessMessageSeller(user.getPhone()); |
| | | try { |
| | | VoiceNotifyMain.call(user.getPhone()); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | } |
| | | return R.ok(orderId); |
| | | } |
| | | |
| | |
| | | <scope>compile</scope> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>com.huaweicloud.sdk</groupId> |
| | | <artifactId>huaweicloud-sdk-voicecall</artifactId> |
| | | <version>3.1.162</version> |
| | | </dependency> |
| | | </dependencies> |
| | | |
| | | </project> |
| | |
| | | } |
| | | |
| | | /** |
| | | * 获取当前UTC+8时间的ISO 8601格式字符串 (例如: 2018-02-12T15:30:20+08:00) |
| | | * |
| | | * @return 当前UTC+8时间的ISO 8601格式字符串 |
| | | */ |
| | | public static String getUtc8Time() |
| | | { |
| | | return OffsetDateTime.now(ZoneOffset.of("+8")).format(DateTimeFormatter.ISO_OFFSET_DATE_TIME); |
| | | } |
| | | |
| | | /** |
| | | * 获取当前UTC时间的ISO 8601格式字符串 (例如: 2018-05-26T00:35:30Z) |
| | | * |
| | | * @return 当前UTC时间的ISO 8601格式字符串 |
| | | */ |
| | | public static String getUtcTime() |
| | | { |
| | | return Instant.now().toString(); |
| | | } |
| | | |
| | | /** |
| | | * 将指定日期转换为UTC时间的ISO 8601格式字符串 (例如: 2018-05-26T00:35:30Z) |
| | | * |
| | | * @param date 指定日期 |
| | | * @return UTC时间的ISO 8601格式字符串 |
| | | */ |
| | | public static String getUtcTime(Date date) |
| | | { |
| | | return date.toInstant().toString(); |
| | | } |
| | | |
| | | /** |
| | | * 计算相差天数 |
| | | */ |
| | | public static int differentDaysByMillisecond(Date date1, Date date2) |
New file |
| | |
| | | package com.ruoyi.common.utils; |
| | | |
| | | import com.ruoyi.common.utils.huawei.*; |
| | | |
| | | import java.util.*; |
| | | import javax.net.ssl.HttpsURLConnection; |
| | | |
| | | |
| | | public class VoiceNotifyMain { |
| | | // 接口返回值 |
| | | private static String status = ""; |
| | | private static String resultcode = ""; |
| | | private static String resultdesc = ""; |
| | | // 语音通知接口返回值 |
| | | private static String sessionId = ""; |
| | | // 语音通知业务类实体 |
| | | public static VoiceNotify callNotifyAPI = new VoiceNotify(); |
| | | |
| | | // 调用接口成功标识 |
| | | private static final String success = "200"; |
| | | |
| | | public static void call(String phone) throws Exception { |
| | | |
| | | // TODO 程序前端要求发起语音通知呼叫,首先使用getplayInfo构造构造playInfoList参数,然后调用doCallNotify方法. |
| | | // 以下代码仅供调试使用,实际开发时请删除 |
| | | // 构造playInfoList参数 |
| | | List<Map<String, Object>> playInfoList = new ArrayList<Map<String, Object>>(); |
| | | // 使用音频文件作为第一段放音内容 |
| | | playInfoList.add(callNotifyAPI.getplayInfo("@DD.wav")); |
| | | // 使用v2.0版本接口的语音通知模板作为第二段放音内容 |
| | | // String templateId = "test"; |
| | | // List<String> templateParas = new ArrayList<String>(); |
| | | // templateParas.add("3"); |
| | | // templateParas.add("1栋保安亭"); |
| | | // playInfoList.add(callNotifyAPI.getplayInfo(templateId, templateParas)); |
| | | // 调用doCallNotify方法 |
| | | VoiceNotifyMain.doCallNotify("+862022519218", "+86"+phone, playInfoList); |
| | | if (status.indexOf(success) != -1) { |
| | | System.out.println(status); |
| | | System.out.println(resultcode + " " + resultdesc); |
| | | System.out.println("The session id is: " + sessionId); |
| | | } |
| | | |
| | | // TODO 需要接收状态和话单时,请参考"呼叫状态和话单通知API"接口实现状态通知和话单的接收和解析 |
| | | // HostingVoiceEventDemoImpl |
| | | } |
| | | |
| | | /* |
| | | * 前端需要发起语音通知呼叫时,调用此方法 该示例只仅体现必选参数,可选参数根据接口文档和实际情况配置. |
| | | */ |
| | | public static void doCallNotify(String displayNbr, String calleeNbr, List<Map<String, Object>> playInfoList) |
| | | throws Exception { |
| | | |
| | | Boolean retry = false; |
| | | // 调用语音通知接口,直至成功 |
| | | do { |
| | | status = callNotifyAPI.callNotifyAPI(displayNbr, calleeNbr, playInfoList); |
| | | if (status.indexOf(success) != -1) { |
| | | retry = false; |
| | | // 调用成功,记录返回的信息. |
| | | resultcode = callNotifyAPI.getResponsePara("resultcode"); |
| | | resultdesc = callNotifyAPI.getResponsePara("resultdesc"); |
| | | sessionId = callNotifyAPI.getResponsePara("sessionId"); |
| | | } else { |
| | | retry = true; |
| | | // 调用失败,获取错误码和错误描述. |
| | | resultcode = callNotifyAPI.getResponsePara("resultcode"); |
| | | resultdesc = callNotifyAPI.getResponsePara("resultdesc"); |
| | | // 处理错误 |
| | | VoiceNotifyMain.processError(); |
| | | } |
| | | } while (retry); |
| | | } |
| | | |
| | | // 当API的返回值不是200时,处理错误. |
| | | private static void processError() throws InterruptedException { |
| | | |
| | | // TODO 根据错误码和错误码描述处理问题 |
| | | // 以下代码仅供调试使用,实际开发时请删除 |
| | | System.out.println(status); |
| | | System.out.println(resultcode + " " + resultdesc); |
| | | System.exit(-1); |
| | | } |
| | | } |
| | | |
| | | class VoiceNotify { |
| | | // 语音通知API的调用地址 |
| | | private String urlCallNotify; |
| | | // 接口响应的消息体 |
| | | private Map<String, String> Responsebody; |
| | | // Https实体 |
| | | private HttpsUtil httpsUtil; |
| | | |
| | | public VoiceNotify() { |
| | | // 商用地址 |
| | | urlCallNotify = Constant.CALL_NOTIFY_COMERCIAL; |
| | | Responsebody = new HashMap<>(); |
| | | } |
| | | |
| | | @SuppressWarnings("unchecked") |
| | | /* |
| | | * 该示例只仅体现必选参数,可选参数根据接口文档和实际情况配置. 该示例不体现参数校验,请根据各参数的格式要求自行实现校验功能. |
| | | * playInfoList为最大个数为5的放音内容参数列表,每个放音内容参数以Map<String,Object>格式存储, |
| | | * 放音内容参数的构造方法请参考getplayInfo方法. |
| | | */ |
| | | public String callNotifyAPI(String displayNbr, String calleeNbr, List<Map<String, Object>> playInfoList) |
| | | throws Exception { |
| | | |
| | | httpsUtil = new HttpsUtil(); |
| | | |
| | | // 忽略证书信任问题 |
| | | httpsUtil.trustAllHttpsCertificates(); |
| | | HttpsURLConnection.setDefaultHostnameVerifier(httpsUtil.hv); |
| | | |
| | | |
| | | |
| | | // 请求Headers |
| | | Map<String, String> headerMap = new HashMap<>(); |
| | | headerMap.put(Constant.HEADER_APP_AUTH, Constant.AUTH_HEADER_VALUE); |
| | | headerMap.put(Constant.HEADER_APP_AKSK, |
| | | StringUtil.buildAKSKHeader(Constant.CALLNOTIFY_APPID, Constant.CALLNOTIFY_SECRET)); |
| | | |
| | | // 构造消息体 |
| | | Map<String, Object> bodys = new HashMap<>(); |
| | | bodys.put("displayNbr", displayNbr);//主叫用户手机终端的来电显示号码。 |
| | | bodys.put("calleeNbr", calleeNbr);//发起呼叫时所拨打的被叫号码。 |
| | | bodys.put("playInfoList", playInfoList);//播放信息列表,最大支持5个,每个播放信息携带的参数都可以不相同。 |
| | | String jsonRequest = JsonUtil.jsonObj2Sting(bodys); |
| | | |
| | | /* |
| | | * Content-Type为application/json且请求方法为post时, 使用doPostJsonGetStatusLine方法构造http |
| | | * request并获取响应. |
| | | */ |
| | | StreamClosedHttpResponse responseCallNotify = httpsUtil.doPostJsonGetStatusLine(urlCallNotify, headerMap, |
| | | jsonRequest); |
| | | |
| | | // 响应的消息体写入Responsebody. |
| | | Responsebody = JsonUtil.jsonString2SimpleObj(responseCallNotify.getContent(), Responsebody.getClass()); |
| | | |
| | | // 返回响应的status. |
| | | return responseCallNotify.getStatusLine().toString(); |
| | | } |
| | | |
| | | /* |
| | | * 构造playInfoList中携带的放音内容参数 使用语音文件或者v1.0版本接口的TTS文本作为放音内容 |
| | | */ |
| | | public Map<String, Object> getplayInfo(String fileorTTS) { |
| | | Map<String, Object> body = new HashMap<String, Object>(); |
| | | // 音频文件只支持wave格式,文件名以.wav结尾 |
| | | if (fileorTTS.endsWith(".wav")) { |
| | | body.put("notifyVoice", fileorTTS); |
| | | } else { |
| | | System.out.println("Only .wav file is supported."); |
| | | } |
| | | return body; |
| | | } |
| | | |
| | | /* |
| | | * 构造playInfoList中携带的放音内容参数 使用v2.0版本接口的TTS模板作为放音内容 重构getplayInfo方法 |
| | | */ |
| | | public Map<String, Object> getplayInfo(String templateId, List<String> templateParas) { |
| | | Map<String, Object> bodys = new HashMap<String, Object>(); |
| | | bodys.put("templateId", templateId); |
| | | bodys.put("templateParas", templateParas); |
| | | return bodys; |
| | | } |
| | | |
| | | // 获取整个响应消息体 |
| | | public Map<String, String> getResponsebody() { |
| | | return this.Responsebody; |
| | | } |
| | | |
| | | // 获取响应消息体中的单个参数 |
| | | public String getResponsePara(String ParaName) { |
| | | return this.Responsebody.get(ParaName); |
| | | } |
| | | } |
New file |
| | |
| | | /* |
| | | * File Name: com.huawei.utils.Constant.java |
| | | * |
| | | * Copyright Notice: |
| | | * Copyright 1998-2008, Huawei Technologies Co., Ltd. ALL Rights Reserved. |
| | | * |
| | | * Warning: This computer software sourcecode is protected by copyright law |
| | | * and international treaties. Unauthorized reproduction or distribution |
| | | * of this sourcecode, or any portion of it, may result in severe civil and |
| | | * criminal penalties, and will be prosecuted to the maximum extent |
| | | * possible under the law. |
| | | */ |
| | | package com.ruoyi.common.utils.huawei; |
| | | |
| | | public class Constant { |
| | | |
| | | // purchase and get : base_url,appid,secret |
| | | |
| | | // please replace the IP and Port, when you use the demo. |
| | | public static final String BASE_URL = "https://rtccall.cn-north-1.myhuaweicloud.cn:443"; |
| | | |
| | | // please replace the appId and secret, when you use the demo. |
| | | public static final String CLICK2CALL_APPID = "*****"; |
| | | public static final String CLICK2CALL_SECRET = "*****"; |
| | | public static final String CALLNOTIFY_APPID = "v3xnlqHu24yMuU1J25l8U6s7sPf3"; |
| | | public static final String CALLNOTIFY_SECRET = "L7gDhEkxfVfEugJGSbXTd5JloxX9"; |
| | | public static final String CALLVERIFY_APPID = "*****"; |
| | | public static final String CALLVERIFY_SECRET = "*****"; |
| | | |
| | | // *************************** The following constants do not need to be |
| | | // modified *********************************// |
| | | |
| | | /* |
| | | * request header |
| | | * 1. HEADER_APP_AUTH |
| | | * 2. HEADER_APP_AKSK |
| | | * 3. AUTH_HEADER_VALUE |
| | | * 4. AKSK_HEADER_FORMAT |
| | | */ |
| | | public static final String HEADER_APP_AUTH = "Authorization"; |
| | | public static final String HEADER_APP_AKSK = "X-AKSK"; |
| | | public static final String AUTH_HEADER_VALUE = "AKSK realm=\"SDP\",profile=\"UsernameToken\",type=\"Appkey\""; |
| | | public static final String AKSK_HEADER_FORMAT = "UsernameToken Username=\"%s\",PasswordDigest=\"%s\",Nonce=\"%s\",Created=\"%s\""; |
| | | |
| | | /* |
| | | * Voice Call: |
| | | * 1. VOICE_CALL_COMERCIAL |
| | | * 2. VOICE_VERIFICATION_COMERCIAL |
| | | * 3. CALL_NOTIFY_COMERCIAL |
| | | * 4. VOICE_FILE_DOWNLOAD |
| | | */ |
| | | public static final String VOICE_CALL_COMERCIAL = BASE_URL + "/rest/httpsessions/click2Call/v2.0"; |
| | | public static final String VOICE_VERIFICATION_COMERCIAL = BASE_URL + "/rest/httpsessions/callVerify/v1.0"; |
| | | public static final String CALL_NOTIFY_COMERCIAL = BASE_URL + "/rest/httpsessions/callnotify/v2.0"; |
| | | public static final String VOICE_FILE_DOWNLOAD = BASE_URL + "/rest/provision/voice/record/v1.0"; |
| | | } |
New file |
| | |
| | | package com.ruoyi.common.utils.huawei; |
| | | |
| | | import org.apache.http.HttpResponse; |
| | | import org.apache.http.NameValuePair; |
| | | import org.apache.http.client.config.RequestConfig; |
| | | import org.apache.http.client.methods.HttpGet; |
| | | import org.apache.http.client.methods.HttpPost; |
| | | import org.apache.http.client.methods.HttpUriRequest; |
| | | import org.apache.http.client.utils.URIBuilder; |
| | | import org.apache.http.conn.ssl.SSLConnectionSocketFactory; |
| | | import org.apache.http.conn.ssl.SSLContextBuilder; |
| | | import org.apache.http.conn.ssl.TrustStrategy; |
| | | import org.apache.http.entity.ContentType; |
| | | import org.apache.http.entity.StringEntity; |
| | | import org.apache.http.impl.client.CloseableHttpClient; |
| | | import org.apache.http.impl.client.DefaultHttpClient; |
| | | import org.apache.http.impl.client.HttpClients; |
| | | |
| | | import java.io.IOException; |
| | | import java.net.URISyntaxException; |
| | | import java.security.KeyManagementException; |
| | | import java.security.KeyStoreException; |
| | | import java.security.NoSuchAlgorithmException; |
| | | import java.security.cert.CertificateException; |
| | | import java.security.cert.X509Certificate; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | import javax.net.ssl.HostnameVerifier; |
| | | import javax.net.ssl.HttpsURLConnection; |
| | | import javax.net.ssl.SSLContext; |
| | | import javax.net.ssl.SSLSession; |
| | | import javax.net.ssl.TrustManager; |
| | | import javax.net.ssl.X509TrustManager; |
| | | |
| | | @SuppressWarnings("deprecation") |
| | | public class HttpsUtil extends DefaultHttpClient { |
| | | public final static String CONTENT_LENGTH = "Content-Length"; |
| | | |
| | | private static CloseableHttpClient httpClient = getHttpClient(); |
| | | |
| | | public static CloseableHttpClient getHttpClient() { |
| | | SSLContext sslcontext = null; |
| | | try { |
| | | sslcontext = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() { |
| | | |
| | | @Override |
| | | public boolean isTrusted(X509Certificate[] arg0, String arg1) throws CertificateException { |
| | | return true; |
| | | } |
| | | }).build(); |
| | | } catch (KeyManagementException e) { |
| | | return null; |
| | | } catch (NoSuchAlgorithmException e) { |
| | | return null; |
| | | } catch (KeyStoreException e) { |
| | | return null; |
| | | } |
| | | |
| | | // Allow TLSv1, TLSv1.1, TLSv1.2 protocol only |
| | | SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext, |
| | | new String[] {"TLSv1", "TLSv1.1", "TLSv1.2"}, null, |
| | | SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); |
| | | |
| | | CloseableHttpClient httpclient = HttpClients.custom() |
| | | .setDefaultRequestConfig(RequestConfig.custom().setRedirectsEnabled(false).build()) |
| | | .setSSLSocketFactory(sslsf).build(); |
| | | |
| | | return httpclient; |
| | | } |
| | | |
| | | public HostnameVerifier hv = new HostnameVerifier() { |
| | | public boolean verify(String urlHostName, SSLSession session) { |
| | | return true; |
| | | } |
| | | }; |
| | | |
| | | public void trustAllHttpsCertificates() throws Exception { |
| | | TrustManager[] trustAllCerts = new TrustManager[1]; |
| | | TrustManager tm = new miTM(); |
| | | trustAllCerts[0] = tm; |
| | | SSLContext sc = SSLContext.getInstance("SSL"); |
| | | sc.init(null, trustAllCerts, null); |
| | | HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); |
| | | } |
| | | |
| | | static class miTM implements TrustManager, X509TrustManager { |
| | | public java.security.cert.X509Certificate[] getAcceptedIssuers() { |
| | | return null; |
| | | } |
| | | |
| | | public boolean isServerTrusted(X509Certificate[] certs) { |
| | | return true; |
| | | } |
| | | |
| | | public boolean isClientTrusted(X509Certificate[] certs) { |
| | | return true; |
| | | } |
| | | |
| | | public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType) |
| | | throws java.security.cert.CertificateException { |
| | | return; |
| | | } |
| | | |
| | | public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType) |
| | | throws java.security.cert.CertificateException { |
| | | return; |
| | | } |
| | | } |
| | | |
| | | public StreamClosedHttpResponse doPostJsonGetStatusLine(String url, Map<String, String> headerMap, String content) { |
| | | HttpPost request = new HttpPost(url); |
| | | addRequestHeader(request, headerMap); |
| | | |
| | | request.setEntity(new StringEntity(content, ContentType.APPLICATION_JSON)); |
| | | |
| | | HttpResponse response = executeHttpRequest(request); |
| | | if (null == response) { |
| | | System.out.println("The response body is null."); |
| | | } |
| | | |
| | | return (StreamClosedHttpResponse) response; |
| | | } |
| | | |
| | | public HttpResponse doGetWithParas(String url, List<NameValuePair> queryParams, Map<String, String> headerMap) |
| | | throws Exception { |
| | | HttpGet request = new HttpGet(); |
| | | addRequestHeader(request, headerMap); |
| | | |
| | | URIBuilder builder; |
| | | try { |
| | | builder = new URIBuilder(url); |
| | | } catch (URISyntaxException e) { |
| | | System.out.printf("URISyntaxException: {}", e); |
| | | throw new Exception(e); |
| | | } |
| | | |
| | | if (queryParams != null && !queryParams.isEmpty()) { |
| | | builder.setParameters(queryParams); |
| | | } |
| | | request.setURI(builder.build()); |
| | | |
| | | return executeHttpRequest(request); |
| | | } |
| | | |
| | | public StreamClosedHttpResponse doGetWithParasGetStatusLine(String url, List<NameValuePair> queryParams, |
| | | Map<String, String> headerMap) throws Exception { |
| | | HttpResponse response = doGetWithParas(url, queryParams, headerMap); |
| | | if (null == response) { |
| | | System.out.println("The response body is null."); |
| | | } |
| | | |
| | | return (StreamClosedHttpResponse) response; |
| | | } |
| | | |
| | | private static void addRequestHeader(HttpUriRequest request, Map<String, String> headerMap) { |
| | | if (headerMap == null) { |
| | | return; |
| | | } |
| | | |
| | | for (String headerName : headerMap.keySet()) { |
| | | if (CONTENT_LENGTH.equalsIgnoreCase(headerName)) { |
| | | continue; |
| | | } |
| | | |
| | | String headerValue = headerMap.get(headerName); |
| | | request.addHeader(headerName, headerValue); |
| | | } |
| | | } |
| | | |
| | | private HttpResponse executeHttpRequest(HttpUriRequest request) { |
| | | HttpResponse response = null; |
| | | |
| | | try { |
| | | response = httpClient.execute(request); |
| | | } catch (Exception e) { |
| | | System.out.println("executeHttpRequest failed."); |
| | | System.out.println(e.getStackTrace()); |
| | | } finally { |
| | | try { |
| | | response = new StreamClosedHttpResponse(response); |
| | | } catch (IOException e) { |
| | | System.out.println("IOException: " + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | return response; |
| | | } |
| | | } |
New file |
| | |
| | | /* |
| | | * Copyright Notice: |
| | | * Copyright 1998-2008, Huawei Technologies Co., Ltd. ALL Rights Reserved. |
| | | * |
| | | * Warning: This computer software sourcecode is protected by copyright law |
| | | * and international treaties. Unauthorized reproduction or distribution |
| | | * of this sourcecode, or any portion of it, may result in severe civil and |
| | | * criminal penalties, and will be prosecuted to the maximum extent |
| | | * possible under the law. |
| | | */ |
| | | |
| | | package com.ruoyi.common.utils.huawei; |
| | | |
| | | import com.fasterxml.jackson.databind.DeserializationFeature; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import com.fasterxml.jackson.databind.SerializationFeature; |
| | | |
| | | import java.io.IOException; |
| | | |
| | | public class JsonUtil { |
| | | |
| | | private static ObjectMapper objectMapper; |
| | | |
| | | static { |
| | | objectMapper = new ObjectMapper(); |
| | | |
| | | // 设置FAIL_ON_EMPTY_BEANS属性,当序列化空对象不要抛异常 |
| | | objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); |
| | | |
| | | // 设置FAIL_ON_UNKNOWN_PROPERTIES属性,当JSON字符串中存在Java对象没有的属性,忽略 |
| | | objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); |
| | | } |
| | | |
| | | /** |
| | | * Convert Object to JsonString |
| | | * |
| | | * @param jsonObj |
| | | * @return |
| | | */ |
| | | public static String jsonObj2Sting(Object jsonObj) { |
| | | String jsonString = null; |
| | | |
| | | try { |
| | | jsonString = objectMapper.writeValueAsString(jsonObj); |
| | | } catch (IOException e) { |
| | | System.out.printf("pasre json Object[{}] to string failed.", jsonString); |
| | | } |
| | | |
| | | return jsonString; |
| | | } |
| | | |
| | | /** |
| | | * Convert JsonString to Simple Object |
| | | * |
| | | * @param jsonString |
| | | * @param cls |
| | | * @return |
| | | */ |
| | | public static <T> T jsonString2SimpleObj(String jsonString, Class<T> cls) { |
| | | T jsonObj = null; |
| | | |
| | | try { |
| | | jsonObj = objectMapper.readValue(jsonString, cls); |
| | | } catch (IOException e) { |
| | | System.out.printf("pasre json Object[{}] to string failed.", jsonString); |
| | | } |
| | | |
| | | return jsonObj; |
| | | } |
| | | } |
New file |
| | |
| | | /* |
| | | * Copyright Notice: |
| | | * Copyright 1998-2008, Huawei Technologies Co., Ltd. ALL Rights Reserved. |
| | | * |
| | | * Warning: This computer software sourcecode is protected by copyright law |
| | | * and international treaties. Unauthorized reproduction or distribution |
| | | * of this sourcecode, or any portion of it, may result in severe civil and |
| | | * criminal penalties, and will be prosecuted to the maximum extent |
| | | * possible under the law. |
| | | */ |
| | | package com.ruoyi.common.utils.huawei; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.Locale; |
| | | |
| | | import org.apache.http.Header; |
| | | import org.apache.http.HeaderIterator; |
| | | import org.apache.http.HttpEntity; |
| | | import org.apache.http.HttpResponse; |
| | | import org.apache.http.ProtocolVersion; |
| | | import org.apache.http.StatusLine; |
| | | import org.apache.http.params.HttpParams; |
| | | |
| | | @SuppressWarnings("deprecation") |
| | | public class StreamClosedHttpResponse implements HttpResponse { |
| | | |
| | | private final HttpResponse original; |
| | | |
| | | private final String content; |
| | | |
| | | public StreamClosedHttpResponse(final HttpResponse original) throws UnsupportedOperationException, IOException { |
| | | this.original = original; |
| | | |
| | | HttpEntity entity = original.getEntity(); |
| | | if (entity != null && entity.isStreaming()) { |
| | | String encoding = entity.getContentEncoding() != null ? entity.getContentEncoding().getValue() : null; |
| | | content = StreamUtil.inputStream2String(entity.getContent(), encoding); |
| | | } else { |
| | | content = null; |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public StatusLine getStatusLine() { |
| | | return original.getStatusLine(); |
| | | } |
| | | |
| | | @Override |
| | | public void setStatusLine(final StatusLine statusline) { |
| | | original.setStatusLine(statusline); |
| | | } |
| | | |
| | | @Override |
| | | public void setStatusLine(final ProtocolVersion ver, final int code) { |
| | | original.setStatusLine(ver, code); |
| | | } |
| | | |
| | | @Override |
| | | public void setStatusLine(final ProtocolVersion ver, final int code, final String reason) { |
| | | original.setStatusLine(ver, code, reason); |
| | | } |
| | | |
| | | @Override |
| | | public void setStatusCode(final int code) throws IllegalStateException { |
| | | original.setStatusCode(code); |
| | | } |
| | | |
| | | @Override |
| | | public void setReasonPhrase(final String reason) throws IllegalStateException { |
| | | original.setReasonPhrase(reason); |
| | | } |
| | | |
| | | @Override |
| | | public HttpEntity getEntity() { |
| | | return original.getEntity(); |
| | | } |
| | | |
| | | @Override |
| | | public void setEntity(final HttpEntity entity) { |
| | | original.setEntity(entity); |
| | | } |
| | | |
| | | @Override |
| | | public Locale getLocale() { |
| | | return original.getLocale(); |
| | | } |
| | | |
| | | @Override |
| | | public void setLocale(final Locale loc) { |
| | | original.setLocale(loc); |
| | | } |
| | | |
| | | @Override |
| | | public ProtocolVersion getProtocolVersion() { |
| | | return original.getProtocolVersion(); |
| | | } |
| | | |
| | | @Override |
| | | public boolean containsHeader(final String name) { |
| | | return original.containsHeader(name); |
| | | } |
| | | |
| | | @Override |
| | | public Header[] getHeaders(final String name) { |
| | | return original.getHeaders(name); |
| | | } |
| | | |
| | | @Override |
| | | public Header getFirstHeader(final String name) { |
| | | return original.getFirstHeader(name); |
| | | } |
| | | |
| | | @Override |
| | | public Header getLastHeader(final String name) { |
| | | return original.getLastHeader(name); |
| | | } |
| | | |
| | | @Override |
| | | public Header[] getAllHeaders() { |
| | | return original.getAllHeaders(); |
| | | } |
| | | |
| | | @Override |
| | | public void addHeader(final Header header) { |
| | | original.addHeader(header); |
| | | } |
| | | |
| | | @Override |
| | | public void addHeader(final String name, final String value) { |
| | | original.addHeader(name, value); |
| | | } |
| | | |
| | | @Override |
| | | public void setHeader(final Header header) { |
| | | original.setHeader(header); |
| | | } |
| | | |
| | | @Override |
| | | public void setHeader(final String name, final String value) { |
| | | original.setHeader(name, value); |
| | | } |
| | | |
| | | @Override |
| | | public void setHeaders(final Header[] headers) { |
| | | original.setHeaders(headers); |
| | | } |
| | | |
| | | @Override |
| | | public void removeHeader(final Header header) { |
| | | original.removeHeader(header); |
| | | } |
| | | |
| | | @Override |
| | | public void removeHeaders(final String name) { |
| | | original.removeHeaders(name); |
| | | } |
| | | |
| | | @Override |
| | | public HeaderIterator headerIterator() { |
| | | return original.headerIterator(); |
| | | } |
| | | |
| | | @Override |
| | | public HeaderIterator headerIterator(final String name) { |
| | | return original.headerIterator(name); |
| | | } |
| | | |
| | | @Override |
| | | public String toString() { |
| | | final StringBuilder sb = new StringBuilder("HttpResponseProxy{"); |
| | | sb.append(original); |
| | | sb.append('}'); |
| | | return sb.toString(); |
| | | } |
| | | |
| | | @Override |
| | | @Deprecated |
| | | public HttpParams getParams() { |
| | | return original.getParams(); |
| | | } |
| | | |
| | | @Override |
| | | @Deprecated |
| | | public void setParams(final HttpParams params) { |
| | | original.setParams(params); |
| | | } |
| | | |
| | | public String getContent() { |
| | | return content; |
| | | } |
| | | } |
New file |
| | |
| | | /* |
| | | * Copyright Notice: |
| | | * Copyright 1998-2008, Huawei Technologies Co., Ltd. ALL Rights Reserved. |
| | | * |
| | | * Warning: This computer software sourcecode is protected by copyright law |
| | | * and international treaties. Unauthorized reproduction or distribution |
| | | * of this sourcecode, or any portion of it, may result in severe civil and |
| | | * criminal penalties, and will be prosecuted to the maximum extent |
| | | * possible under the law. |
| | | */ |
| | | package com.ruoyi.common.utils.huawei; |
| | | |
| | | import java.io.Closeable; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.io.InputStreamReader; |
| | | |
| | | public class StreamUtil { |
| | | |
| | | private static final String DEFAULT_ENCODING = "utf-8"; |
| | | |
| | | public static String inputStream2String(InputStream in, String charsetName) { |
| | | if (in == null) { |
| | | return null; |
| | | } |
| | | |
| | | InputStreamReader inReader = null; |
| | | |
| | | try { |
| | | if (StringUtil.strIsNullOrEmpty(charsetName)) { |
| | | inReader = new InputStreamReader(in, DEFAULT_ENCODING); |
| | | } else { |
| | | inReader = new InputStreamReader(in, charsetName); |
| | | } |
| | | |
| | | int readLen = 0; |
| | | char[] buffer = new char[1024]; |
| | | StringBuilder strBuf = new StringBuilder(); |
| | | while ((readLen = inReader.read(buffer)) != -1) { |
| | | strBuf.append(buffer, 0, readLen); |
| | | } |
| | | |
| | | return strBuf.toString(); |
| | | } catch (IOException e) { |
| | | System.out.println(e); |
| | | } finally { |
| | | closeStream(inReader); |
| | | } |
| | | |
| | | return null; |
| | | } |
| | | |
| | | public static void closeStream(Closeable closeable) { |
| | | if (closeable != null) { |
| | | try { |
| | | closeable.close(); |
| | | } catch (IOException e) { |
| | | System.out.println(e); |
| | | } |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | /* |
| | | * Copyright Notice: |
| | | * Copyright 1998-2008, Huawei Technologies Co., Ltd. ALL Rights Reserved. |
| | | * |
| | | * Warning: This computer software sourcecode is protected by copyright law |
| | | * and international treaties. Unauthorized reproduction or distribution |
| | | * of this sourcecode, or any portion of it, may result in severe civil and |
| | | * criminal penalties, and will be prosecuted to the maximum extent |
| | | * possible under the law. |
| | | */ |
| | | package com.ruoyi.common.utils.huawei; |
| | | |
| | | //import java.nio.charset.Charset; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Base64; // JDK version≥1.8 |
| | | import java.util.Calendar; |
| | | import java.util.Locale; |
| | | import java.util.TimeZone; |
| | | import java.util.UUID; |
| | | |
| | | //import org.apache.commons.codec.binary.Base64; //JDK version<1.8 |
| | | import javax.crypto.Mac; |
| | | import javax.crypto.spec.SecretKeySpec; |
| | | |
| | | public class StringUtil { |
| | | |
| | | public static boolean strIsNullOrEmpty(String s) { |
| | | return (null == s || s.trim().length() < 1); |
| | | } |
| | | |
| | | public static String buildAKSKHeader(String appKey, String appSecret) throws Exception { |
| | | if (StringUtil.strIsNullOrEmpty(appKey) || StringUtil.strIsNullOrEmpty(appSecret)) { |
| | | return null; |
| | | } |
| | | |
| | | SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); |
| | | format.setTimeZone(TimeZone.getTimeZone("UTC")); |
| | | Calendar calendar = Calendar.getInstance(); |
| | | String time = format.format(calendar.getTime()); |
| | | String stNonce = UUID.randomUUID().toString().replace("-", "").toUpperCase(Locale.ROOT); |
| | | String str = stNonce + time; |
| | | Mac mac = Mac.getInstance("HmacSHA256"); |
| | | mac.init(new SecretKeySpec(appSecret.getBytes(StandardCharsets.UTF_8), "HmacSHA256")); |
| | | byte[] authBytes = mac.doFinal(str.getBytes(StandardCharsets.UTF_8)); |
| | | String passwordDigestBase64Str = encodeBase64(authBytes); |
| | | return String.format(Constant.AKSK_HEADER_FORMAT, appKey, passwordDigestBase64Str, stNonce, time); |
| | | } |
| | | |
| | | private static String encodeBase64(byte[] bytes) { |
| | | if (bytes.length == 0) { |
| | | return null; |
| | | } else { |
| | | return new String(org.apache.commons.codec.binary.Base64.encodeBase64(bytes), StandardCharsets.UTF_8); |
| | | } |
| | | } |
| | | } |
| | |
| | | private Integer highTechEnterpriseTechnology; |
| | | |
| | | @ApiModelProperty("发证时间") |
| | | private Date highTechEnterpriseTechnologyTime; |
| | | private String highTechEnterpriseTechnologyTime; |
| | | /** |
| | | * 社保缴纳0无1有 |
| | | */ |
| | |
| | | private Integer highTechEnterpriseTechnology; |
| | | |
| | | @ApiModelProperty("发证时间") |
| | | private Date highTechEnterpriseTechnologyTime; |
| | | private String highTechEnterpriseTechnologyTime; |
| | | /** |
| | | * 社保缴纳0无1有 |
| | | */ |
| | |
| | | @TableField("high_tech_enterprise_technology") |
| | | private Integer highTechEnterpriseTechnology; |
| | | |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") |
| | | @ApiModelProperty("发证时间") |
| | | @TableField("high_tech_enterprise_technology_time") |
| | | private Date highTechEnterpriseTechnologyTime; |
| | | private String highTechEnterpriseTechnologyTime; |
| | | /** |
| | | * 社保缴纳0无1有 |
| | | */ |
| | |
| | | order.setOutTradeNo(notifyResult.getOutTradeNo()); |
| | | order.setTransactionId(notifyResult.getTransactionId()); |
| | | TbCompany company = companyService.getById(order.getCompanyId()); |
| | | // 生成记录 看是否分佣 金额 发布人 |
| | | TbUser user = userService.getById(company.getUserId()); |
| | | // 购买人 生成记录 看是否分佣 金额 发布人 如A用户售卖100元公司 C用户购买这个公司 B是C的上级 抽10% 平台抽成20% 那么A应得80 B得2 平台得18 |
| | | TbUser user = userService.getById(order.getUserId()); |
| | | TbSystemConfig config = configService.getOne(new LambdaQueryWrapper<TbSystemConfig>().eq(TbSystemConfig::getType, 3)); |
| | | if(config!=null){ |
| | | JSONObject jsonObject = JSONObject.parseObject(config.getContent()); |
| | |
| | | BigDecimal userCommission = new BigDecimal(jsonObject.get("user").toString()); |
| | | BigDecimal price = order.getPrice(); |
| | | BigDecimal divide = platformCommission.divide(new BigDecimal("100")); |
| | | // 平台抽佣 |
| | | BigDecimal platformCommissionMoney = divide.multiply(price).setScale(2, RoundingMode.HALF_UP); |
| | | |
| | | // 购买人是否绑定了用户 且次数足够 |
| | | if(StringUtils.isNotEmpty(user.getInviteId()) && user.getInviteNum()>0){ |
| | | BigDecimal divide1 = userCommission.divide(new BigDecimal("100")); |
| | | BigDecimal userCommissionMoney = divide1.multiply(price).setScale(2, RoundingMode.HALF_UP); |
| | | BigDecimal userCommissionMoney = divide1.multiply(platformCommissionMoney).setScale(2, RoundingMode.HALF_UP); |
| | | order.setCommissionPrice(userCommissionMoney); |
| | | |
| | | platformCommissionMoney = platformCommissionMoney.subtract(userCommissionMoney); |
| | | |
| | | if(userCommissionMoney.doubleValue()>0){ |
| | | TbUser shareUser = userService.getById(user.getInviteId()); |
| | | if(shareUser!=null){ |
| | |
| | | @ApiModelProperty("是否高新技术 0否1是") |
| | | private Integer highTechEnterpriseTechnology; |
| | | |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") |
| | | @ApiModelProperty("发证时间") |
| | | private Date highTechEnterpriseTechnologyTime; |
| | | private String highTechEnterpriseTechnologyTime; |
| | | |
| | | @ApiModelProperty("预估注册资金 企查查") |
| | | private String realRegisteredCapital; |