uni-app在线消息推送java和vue

//uni-app在线消息推送java端代码
package com.zj.app_signin.controller;

import com.gexin.rp.sdk.base.IPushResult;
import com.gexin.rp.sdk.base.impl.AppMessage;
import com.gexin.rp.sdk.http.IGtPush;
import com.gexin.rp.sdk.template.NotificationTemplate;
import com.gexin.rp.sdk.template.style.Style0;
import org.springframework.core.io.support.PropertiesLoaderUtils;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;

import static java.lang.System.out;

public class AppPush {
private static Map<String, Object> profileMap = getProfileByPropertiesLoaderUtils();

// private static Object o = profileMap.get(“maxlaborhour”);

// STEP1:获取应用基本信息
//我这边是通过去配置文件的值的方式取值的,你们大可直接等于那个appid的值就好了,下面几个属性依次类推
private static String appId = profileMap.get("appId")+"";
private static String appKey = profileMap.get("appKey")+"";
private static String masterSecret =profileMap.get("masterSecret")+"";
private static String url = profileMap.get("url")+"";

public static void appMessageStart(){
 try {
     IGtPush push = new IGtPush(url, appKey, masterSecret);

     Style0 style = new Style0();
     // STEP2:设置推送标题、推送内容
     style.setTitle("消息标题");
     style.setText("消息内容");
     // 注释采用默认图标
     // style.setLogo("push.png");  // 设置推送图标
     // STEP3:设置响铃、震动等推送效果
     style.setRing(true);  // 设置响铃
     style.setVibrate(true);  // 设置震动

     // STEP4:选择通知模板
     NotificationTemplate template = new NotificationTemplate();
     template.setAppId(appId);
     template.setAppkey(appKey);
     template.setStyle(style);
     // 点击消息打开应用
     template.setTransmissionType(1);
     // 传递自定义消息
     template.setTransmissionContent("自定义消息,可以是json 字符串");


     // STEP5:定义"AppMessage"类型消息对象,设置推送消息有效期等推送参数
     List<String> appIds = new ArrayList<String>();
     appIds.add(appId);
     AppMessage message = new AppMessage();
     message.setData(template);
     message.setAppIdList(appIds);
     message.setOffline(true);
     message.setOfflineExpireTime(1000 * 600);  // 时间单位为毫秒

     // STEP6:执行推送
     IPushResult ret = push.pushMessageToApp(message);
     System.out.println(ret.getResponse().toString());
 }
 catch (Exception e){
     out.println(e);
 }
 finally {

 }



}


/**
 * @return Map<String, Object>
 * @Title: getProfileByPropertiesLoaderUtils
 * @Description: Spring 提供的 PropertiesLoaderUtils 允许您直接通过基于类路径的文件地址加载属性资源
 * 最大的好处就是:实时加载配置文件,修改后立即生效,不必重启
 */
public static Map<String, Object> getProfileByPropertiesLoaderUtils() {
    Properties props = new Properties();
    Map<String, Object> profileMap = new ConcurrentHashMap<>();
    try {
        props = PropertiesLoaderUtils.loadAllProperties("necessary.properties");
        for (Object key : props.keySet()) {
            profileMap.put(key.toString(), props.getProperty(key.toString()));
        }
    } catch (IOException e) {
        out.println(e);
    }
    return profileMap;
}

}

//vue端代码 在app.vue的export default添加如下代码
getCid() {
setTimeout(async () => { // 定时器的作用是防止获取cid有延迟
var pinf = plus.push.getClientInfo();
var cid = pinf.clientid; //客户端标识,要上传到你们的服务端
}, 1000);
}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值