xiongzhu vor 3 Jahren
Ursprung
Commit
4a65c56b20

+ 13 - 5
src/main/java/com/izouma/nineth/push/PushUtils.java

@@ -21,7 +21,7 @@ public class PushUtils {
         }
     }
 
-    public void sendAndroidBroadcast(String ticker, String title, String text) throws Exception {
+    public void sendAndroidBroadcast(String ticker, String title, String text, boolean production) throws Exception {
         AndroidBroadcast broadcast = new AndroidBroadcast(appkey, appMasterSecret);
         broadcast.setTicker(ticker);
         broadcast.setTitle(title);
@@ -30,7 +30,11 @@ public class PushUtils {
         broadcast.setDisplayType(AndroidNotification.DisplayType.NOTIFICATION);
         // TODO Set 'production_mode' to 'false' if it's a test device.
         // For how to register a test device, please see the developer doc.
-        broadcast.setProductionMode();
+        if (production) {
+            broadcast.setProductionMode();
+        } else {
+            broadcast.setTestMode();
+        }
         // Set customized fields
 //        broadcast.setExtraField("test", "helloworld");
         //厂商通道相关参数
@@ -156,7 +160,7 @@ public class PushUtils {
         client.send(filecast);
     }
 
-    public void sendIOSBroadcast(String title, String text) throws Exception {
+    public void sendIOSBroadcast(String title, String text, boolean production) throws Exception {
         IOSBroadcast broadcast = new IOSBroadcast(appkey, appMasterSecret);
         //alert值设置为字符串
         //broadcast.setAlert("IOS 广播测试");
@@ -165,7 +169,11 @@ public class PushUtils {
         broadcast.setBadge(0);
         broadcast.setSound("default");
         // TODO set 'production_mode' to 'true' if your app is under production mode
-        broadcast.setTestMode();
+        if (production) {
+            broadcast.setProductionMode();
+        } else {
+            broadcast.setTestMode();
+        }
         // Set customized fields
         broadcast.setCustomizedField("test", "helloworld");
         client.send(broadcast);
@@ -257,7 +265,7 @@ public class PushUtils {
     public static void main(String[] args) {
         try {
             new PushUtils("62b5753a05844627b5c56bc8", "lynwia75tojrokcmqu9nyiukhjdrefof")
-                    .sendIOSBroadcast("test", "123");
+                    .sendIOSBroadcast("test", "123", false);
         } catch (Exception ex) {
             ex.printStackTrace();
         }

+ 4 - 4
src/main/java/com/izouma/nineth/web/PushController.java

@@ -11,10 +11,10 @@ import org.springframework.web.bind.annotation.RestController;
 public class PushController extends BaseController {
 
     @PostMapping("/broadcast")
-    public void broadcast(@RequestParam String title, @RequestParam String text) throws Exception {
-//        new PushUtils("62b5753a05844627b5c56bc8", "dlo3bqifmuuvbpmodmcyc2xnh0b1fphi")
-//                .sendAndroidBroadcast(title, title, text);
+    public void broadcast(@RequestParam String title, @RequestParam String text, @RequestParam boolean production) throws Exception {
+        new PushUtils("62b5753a05844627b5c56bc8", "dlo3bqifmuuvbpmodmcyc2xnh0b1fphi")
+                .sendAndroidBroadcast(title, title, text, production);
         new PushUtils("62b5751a05844627b5c56b51", "lynwia75tojrokcmqu9nyiukhjdrefof")
-                .sendIOSBroadcast(title, text);
+                .sendIOSBroadcast(title, text, production);
     }
 }

+ 10 - 1
src/main/vue/src/views/Push.vue

@@ -37,9 +37,18 @@ export default {
             this.$refs.form
                 .validate()
                 .then(res => {
+                    return this.$confirm('确认发送?');
+                })
+                .then(() => {
                     this.pushing = true;
                     this.$http
-                        .post('/push/broadcast', this.formData)
+                        .post('/push/broadcast', {
+                            ...this.formData,
+                            production:
+                                'raex.vip' === location.host ||
+                                'www.raex.vip' === location.host ||
+                                'admin.raex.vip' === location.host
+                        })
                         .then(res => {
                             this.$message.success('发送成功');
                             this.pushing = false;