¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.system.api.duix; |
| | | |
| | | |
| | | import org.springframework.stereotype.Service; |
| | | import com.auth0.jwt.JWT; |
| | | import com.auth0.jwt.algorithms.Algorithm; |
| | | import java.util.Calendar; |
| | | import java.util.Date; |
| | | import java.util.Map; |
| | | import java.io.BufferedReader; |
| | | import java.io.InputStreamReader; |
| | | import java.net.HttpURLConnection; |
| | | import java.net.URL; |
| | | |
| | | @Service |
| | | public class DuixApiImpl implements DuixApi{ |
| | | |
| | | /** |
| | | * çætouken |
| | | * appId string ä¼è¯æ è¯ï¼ä¼è¯å建æååè·å xxxxxxx |
| | | * appKey string ä¼è¯å¯é¥ï¼ä¼è¯å建æååè·å xxxxxxx |
| | | * sigExp Integer ç¾åæææ¶é´ï¼åä½ç§ 18000 |
| | | */ |
| | | public static String createSig(String appId, String appKey, int sigExp) { |
| | | Calendar nowTime = Calendar.getInstance(); |
| | | nowTime.add(Calendar.SECOND, sigExp); |
| | | Date expiresDate = nowTime.getTime(); |
| | | return JWT.create() |
| | | //Release date |
| | | .withIssuedAt(new Date()) |
| | | //effective time |
| | | .withExpiresAt(expiresDate) |
| | | //load |
| | | .withClaim("appId", appId) |
| | | //encryption |
| | | .sign(Algorithm.HMAC256(appKey)); |
| | | } |
| | | |
| | | /** |
| | | * è·åAPP宿¶å¹¶åå· |
| | | * æ¥è¯¢æå® APP ä¸çå¹¶åå· |
| | | * appId åºç¨ç¨åº å符串 æ¥è¯¢ ä»å¹³å°å建ç APPID |
| | | * |
| | | * @param appId |
| | | */ |
| | | @Override |
| | | public Map<String, Object> getAppConcurrent(String appId) { |
| | | String urlString = "https://your-domain.com/duix-openapi-v2/sdk/v2/getconcurrentNumber?appId=" + appId; |
| | | |
| | | try { |
| | | URL url = new URL(urlString); |
| | | HttpURLConnection conn = (HttpURLConnection) url.openConnection(); |
| | | |
| | | // è®¾ç½®è¯·æ±æ¹æ³ä¸º GET |
| | | conn.setRequestMethod("GET"); |
| | | |
| | | // 设置请æ±å¤´ï¼å¦æéè¦èº«ä»½éªè¯ï¼æ¯å¦tokenï¼å¯ä»¥æ·»å å¦ä¸å
å®¹ï¼ |
| | | // conn.setRequestProperty("Authorization", "Bearer your_token"); |
| | | |
| | | int responseCode = conn.getResponseCode(); |
| | | System.out.println("Response Code: " + responseCode); |
| | | |
| | | BufferedReader in = new BufferedReader(new InputStreamReader( |
| | | conn.getInputStream())); |
| | | String inputLine; |
| | | StringBuilder response = new StringBuilder(); |
| | | |
| | | while ((inputLine = in.readLine()) != null) { |
| | | response.append(inputLine); |
| | | } |
| | | in.close(); |
| | | |
| | | // æå°è¿åç»æ |
| | | System.out.println("Response: " + response.toString()); |
| | | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return null; |
| | | } |
| | | } |