admin
2018-12-27 8b822fee307f5c5152c6d8d9c26f4031c1a53604
VIVO基础推送
3个文件已添加
177 ■■■■■ 已修改文件
fanli/src/main/java/com/yeshi/fanli/exception/push/VIVOPushException.java 30 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/util/push/VIVOPushUtil.java 90 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/vo/order/ChannelDataStatisticVO.java 57 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/exception/push/VIVOPushException.java
New file
@@ -0,0 +1,30 @@
package com.yeshi.fanli.exception.push;
public class VIVOPushException extends Exception {
    private static final long serialVersionUID = 1L;
    private int code;
    private String msg;
    public VIVOPushException() {}
    public VIVOPushException(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }
    public int getCode() {
        return code;
    }
    public String getMsg() {
        return msg;
    }
    @Override
    public String getMessage() {
        return this.msg;
    }
}
fanli/src/main/java/com/yeshi/fanli/util/push/VIVOPushUtil.java
New file
@@ -0,0 +1,90 @@
package com.yeshi.fanli.util.push;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.StringRequestEntity;
import org.yeshi.utils.HttpUtil;
import com.yeshi.fanli.exception.push.VIVOPushException;
import com.yeshi.fanli.util.StringUtil;
import net.sf.json.JSONObject;
/**
 * VIVO的推送帮助
 *
 * @author Administrator
 *
 */
public class VIVOPushUtil {
    /**
     * POST请求
     *
     * @param url
     * @param body
     * @param headers
     * @return
     */
    private static String post(String url, String body, Map<String, String> headers) {
        HttpClient httpClient = new HttpClient();
        PostMethod pm = new PostMethod(url);
        try {
            pm.setRequestEntity(new StringRequestEntity(body, "application/json", "UTF-8"));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        if (headers != null) {
            Iterator<String> its = headers.keySet().iterator();
            while (its.hasNext()) {
                String key = its.next();
                pm.setRequestHeader(key, headers.get(key));
            }
        }
        try {
            httpClient.executeMethod(pm);
            return pm.getResponseBodyAsString();
        } catch (HttpException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
    /**
     * 获取授权码
     *
     * @param appId
     * @param appKey
     * @param appSecret
     * @return
     * @throws VIVOPushException
     */
    public static String getAuthToken(String appId, String appKey, String appSecret) throws VIVOPushException {
        JSONObject params = new JSONObject();
        long timestamp = System.currentTimeMillis();
        params.put("appId", appId);
        params.put("appKey", appKey);
        params.put("timestamp", timestamp);
        params.put("sign", StringUtil.Md5(appId + appKey + timestamp + appSecret));
        String result = post("https://host:port/message/auth", params.toString(), null);
        JSONObject resultJson = JSONObject.fromObject(result);
        if (resultJson.optInt("result") != 0)
            throw new VIVOPushException(resultJson.optInt("result"), resultJson.optString("desc"));
        return resultJson.optString("authToken");
    }
}
fanli/src/main/java/com/yeshi/fanli/vo/order/ChannelDataStatisticVO.java
New file
@@ -0,0 +1,57 @@
package com.yeshi.fanli.vo.order;
import java.math.BigDecimal;
/**
 * 渠道数据统计
 *
 * @author Administrator
 *
 */
public class ChannelDataStatisticVO {
    private String date;// 日期
    private BigDecimal estimate;// 佣金
    private BigDecimal payMoney;// 支付金额
    private int userCount;// 新增用户数量
    private int orderCount;// 订单数量
    public String getDate() {
        return date;
    }
    public void setDate(String date) {
        this.date = date;
    }
    public BigDecimal getEstimate() {
        return estimate;
    }
    public void setEstimate(BigDecimal estimate) {
        this.estimate = estimate;
    }
    public BigDecimal getPayMoney() {
        return payMoney;
    }
    public void setPayMoney(BigDecimal payMoney) {
        this.payMoney = payMoney;
    }
    public int getUserCount() {
        return userCount;
    }
    public void setUserCount(int userCount) {
        this.userCount = userCount;
    }
    public int getOrderCount() {
        return orderCount;
    }
    public void setOrderCount(int orderCount) {
        this.orderCount = orderCount;
    }
}