无关风月
2 天以前 1442f149019ee0590389abd7a88a79c4d9b59034
ruoyi-service/ruoyi-admin/src/main/java/com/ruoyi/admin/utils/DescribeInstances.java
@@ -10,8 +10,69 @@
import com.tencentcloudapi.cvm.v20170312.models.DescribeInstancesResponse;
import com.tencentcloudapi.ocr.v20181119.OcrClient;
import com.tencentcloudapi.ocr.v20181119.models.*;
import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;
import java.util.HashMap;
import java.util.Map;
public class DescribeInstances {
    public static  JSONObject ocr(String address){
        String host = "https://addre.market.alicloudapi.com";
        String path = "/format";
        String method = "GET";
        String appcode = "0efeed6a5fe94240b143fec8910c5053";
        Map<String, String> headers = new HashMap<String, String>();
        //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
        headers.put("Authorization", "APPCODE " + appcode);
        Map<String, String> querys = new HashMap<String, String>();
        querys.put("text", address);
        try {
            /**
             * 重要提示如下:
             * HttpUtils请从
             * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java
             * 下载
             *
             * 相应的依赖请参照
             * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml
             */
            HttpResponse response = HttpUtils.doGet(host, path, method, headers, querys);
            System.out.println();
            String string = EntityUtils.toString(response.getEntity());
            JSONObject json = JSON.parseObject(string);
            // 获取 data 对象
            JSONObject data = json.getJSONObject("data");
            // 提取所需的字段
            String address1 = data.getString("address");
            String person1 = data.getString("person");
            String phonenum1 = data.getString("phonenum");
            // 打印结果
            System.out.println("Address: " + address1);
            System.out.println("Person: " + person1);
            System.out.println("Phone Number: " + phonenum1);
            AddressDto addressDto = new AddressDto();
            addressDto.setAddress(address1);
            addressDto.setName(person1);
            addressDto.setPhone(phonenum1);
            return data;
            //获取response的body
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new JSONObject();
    }
    public static AddressDto  orcr(String args) {
        try {
            // 为了保护密钥安全,建议将密钥设置在环境变量中或者配置文件中,请参考本文凭证管理章节。