package com.nokia.domainb.capability;

import java.util.Date;

import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;

/**
 * 用户信用度查询 json_microservice_users_getEcredit
 * 不支持post方法
 */
public class GetEcredit extends AbstractQuery {
    private static final String url = "http://192.168.70.130:8000/api/microservice/users/getEcredit/v1";
    private static final String urlTest = "http://10.124.150.230:8000/api/microservice/users/getEcredit/v1";

    public String query(String phoneNumber) {
        return query(phoneNumber, false);
    }

    public String query(String phoneNumber, boolean test) {
        String realUrl = test ? urlTest : url;

        StringBuilder sb = new StringBuilder();
        sb.append("SERIAL_NUMBER=").append(phoneNumber);
        sb.append("&").append("SERVICE_CLASS_CODE=").append("50");
        // sb.append("&").append("PARA_ID").append("undefined");
        // sb.append("&").append("AREA_CODE").append("undefined");
        // sb.append("&").append("PARA_VALUE").append("undefined");
        sb.append("&").append("APP_ID=").append(appId);

        Date date = new Date();
        String timeStamp = getTimeStamp(date);
        String transId = getTransId(date);
        sb.append("&").append("TIMESTAMP=").append(timeStamp);
        sb.append("&").append("TRANS_ID=").append(transId);
        sb.append("&").append("TOKEN=").append(getToken(timeStamp, transId, test));

        RestTemplate restTemplate = new RestTemplate();
        System.out.println(sb.toString());
        ResponseEntity<String> response = restTemplate.getForEntity(realUrl + "?" + sb.toString(), String.class);
        return response.getBody();

        // 不支持post方法
        // COMPConnection compConnection = new COMPJsonConnection(appId, realAppSecret);
        // Map<String, Object> uniBssBody = new HashMap<>();
        // uniBssBody.put("SERIAL_NUMBER", phoneNumber);
        // uniBssBody.put("SERVICE_CLASS_CODE", "50");
        // return compConnection.excute(Const.HttpMethodType.POST, realUrl, uniBssBody,
        // false);
    }
}
