Administrator
2018-11-09 215b69ed5f01ab8c08bc4df749ed9fe95c79524d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package com.yeshi.fanli.controller.client;
 
import java.io.PrintWriter;
 
import javax.annotation.Resource;
 
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
 
import com.yeshi.fanli.entity.accept.AcceptData;
import com.yeshi.fanli.entity.push.DeviceTokenIOS;
import com.yeshi.fanli.entity.system.System;
import com.yeshi.fanli.service.inter.config.SystemService;
import com.yeshi.fanli.service.inter.push.DeviceTokenHWService;
import com.yeshi.fanli.service.inter.push.IOSPushService;
import com.yeshi.fanli.service.inter.push.PushRecordService;
import com.yeshi.fanli.util.StringUtil;
import org.yeshi.utils.JsonUtil;
 
@Controller
@RequestMapping(value = "api/v1/push")
public class PushController {
 
    @Resource
    private SystemService systemService;
 
    @Resource
    private PushRecordService pushRecordService;
 
    @Resource
    private IOSPushService iosPushService;
 
    @Resource
    private DeviceTokenHWService deviceTokenHWService;
 
    @RequestMapping(value = "callback", method = RequestMethod.POST)
    public void callback(AcceptData acceptData, String pushId, PrintWriter out) {
        System system = systemService.getSystemCache(acceptData.getPlatform(), acceptData.getPackages());
        if (system == null) {
            out.print(JsonUtil.loadFalseResult("不存在该系统"));
            return;
        }
        int platform = system.getPlatform();
        if (platform == 1) {
            pushRecordService.increaseByAndroid(pushId);
        } else {
            pushRecordService.increaseByIOS(pushId);
        }
        out.print(JsonUtil.loadTrueResult("回调成功"));
    }
 
    /**
     * 
     * 插入苹果推送的deviceToken
     * 
     * @author mawurui createTime 2018年5月8日 下午4:15:44
     * @param deviceToken
     */
    @RequestMapping(value = "/insertDeviceToken", method = RequestMethod.POST)
    public void insertIOSDeviceToken(AcceptData acceptData, String deviceToken, PrintWriter out) {
        if (!StringUtil.isNullOrEmpty(acceptData.getDevice()) && !StringUtil.isNullOrEmpty(deviceToken)) {
            DeviceTokenIOS deviceTokenIOS = iosPushService.getDeviceTokenByDevice(acceptData.getDevice());
            if (deviceTokenIOS == null)
                iosPushService.addDeviceToken(null, Integer.parseInt(acceptData.getVersion()), deviceToken,
                        acceptData.getDevice());
            else {
                deviceTokenIOS.setDeviceToken(deviceToken);
                iosPushService.updateDeviceToken(deviceTokenIOS);
            }
            out.print(JsonUtil.loadTrue(0, null, "成功"));
        }
    }
 
    /**
     * IOS推送 方法说明: 将用户id和deviceToken绑定
     * 
     * @author mawurui createTime 2018年5月8日 下午4:29:45
     * @param uid
     * @param deviceToken
     */
 
    // 传一个device 如果存在device 根据device执行update操作 , 如果不存在 都执行insert操作三个参数
    @RequestMapping(value = "/uidBindDeviceToken", method = RequestMethod.POST)
    public void uidBindIOSDeviceToken(AcceptData acceptData, Long uid, String deviceToken, PrintWriter out) {
        if (uid != null && uid != 0 && !StringUtil.isNullOrEmpty(deviceToken)) {
            DeviceTokenIOS deviceTokenIOS = iosPushService.getDeviceTokenByDevice(acceptData.getDevice());
            if (deviceTokenIOS != null) {
                if (!StringUtil.isNullOrEmpty(deviceToken))
                    deviceTokenIOS.setDeviceToken(deviceToken);
                deviceTokenIOS.setUid(uid);
                deviceTokenIOS.setVersion(Integer.parseInt(acceptData.getVersion()));
                iosPushService.updateDeviceToken(deviceTokenIOS);
            } else {
                iosPushService.addDeviceToken(uid, Integer.parseInt(acceptData.getVersion()), deviceToken,
                        acceptData.getDevice());
            }
        }
    }
 
    /**
     * IOS推送 方法说明: 解绑
     * 
     * @author mawurui createTime 2018年5月9日 上午9:49:58
     * @param deviceToken
     */
    @RequestMapping(value = "/unBind", method = RequestMethod.POST)
    public void unBind(AcceptData acceptData, String deviceToken, PrintWriter out) {
        if (deviceToken != null && !"".equals(deviceToken)) {
            DeviceTokenIOS deviceTokenIOS = iosPushService.getDeviceTokenByDevice(acceptData.getDevice());
            if (deviceTokenIOS != null) {
                deviceTokenIOS.setUid(null);
                iosPushService.updateDeviceToken(deviceTokenIOS);
            }
            out.print(JsonUtil.loadTrue(0, null, "解绑成功"));
        }
    }
 
    /**
     * 绑定华为推送
     * 
     * @param acceptData
     * @param token
     *            -华为token
     * @param uid
     *            -用户ID
     * @param out
     */
    @RequestMapping(value = "/bindHWPush", method = RequestMethod.POST)
    public void bindHWDeviceToken(AcceptData acceptData, String token, Long uid, PrintWriter out) {
        deviceTokenHWService.addDeviceToken(token, acceptData.getDevice(), uid);
        out.print(JsonUtil.loadTrueResult("成功"));
    }
 
    /**
     * 解绑推送
     * 
     * @param acceptData
     * @param out
     */
    @RequestMapping(value = "/unBindHWPush", method = RequestMethod.POST)
    public void unBindHWDeviceToken(AcceptData acceptData, PrintWriter out) {
        deviceTokenHWService.unBindDeviceToken(acceptData.getDevice());
        out.print(JsonUtil.loadTrueResult("成功"));
    }
 
}