package selling.sunshine.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter;
import com.sun.jersey.core.util.MultivaluedMapImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import selling.sunshine.service.MessageService;
import selling.sunshine.utils.PlatformConfig;
import selling.sunshine.utils.ResponseCode;
import selling.sunshine.utils.ResultData;

import javax.ws.rs.core.MediaType;

/**
 * Created by sunshine on 6/1/16.
 */
@Service
public class MessageServiceImpl implements MessageService {
    private Logger logger = LoggerFactory.getLogger(MessageServiceImpl.class);

    @Override
    public ResultData send(String phone, String message) {
        ResultData result = new ResultData();
        Client client = Client.create();
        client.addFilter(new HTTPBasicAuthFilter("api", PlatformConfig.getValue("message_api_key")));
        WebResource webResource = client.resource(
                "http://sms-api.luosimao.com/v1/send.json");
        MultivaluedMapImpl formData = new MultivaluedMapImpl();
        formData.add("mobile", phone);
        formData.add("message", message);
        ClientResponse response = webResource.type(MediaType.APPLICATION_FORM_URLENCODED).
                post(ClientResponse.class, formData);
        logger.debug(JSONObject.toJSONString(response));
        int status = response.getStatus();
        if (status != HttpStatus.OK.value()) {
            result.setResponseCode(ResponseCode.RESPONSE_ERROR);
            result.setDescription(JSONObject.toJSONString(response));
            logger.error(JSONObject.toJSONString(response));
        }
        return result;
    }
}

@@ -1393,24 +1393,55 @@
 , message);%0A
+        logger.debug(message);%0A
         Clie

add message