doPatient
doPatient
  • 发布:2019-10-15 19:47
  • 更新:2019-10-16 10:17
  • 阅读:2312

uniapp接入推送模块,选择的是unipush,后端如何开发?也是用个推的包进行开发?

分类:uni-app

uniapp接入推送模块,选择的是unipush,后端如何开发?也是用个推的包进行开发?

2019-10-15 19:47 负责人:无 分享
已邀请:
1***@qq.com

1***@qq.com

几个月前写过一次,采用的是离线打包,测试没有问题,版本更新了不知道有没有变化.大体如下:

1.首先要开通upush服务(官方有文档)

  1. 开通对应厂商服务(小米,华为,oppo...)拿到相应的参数,appid,secret...

  2. androidstudio的配置,我只用了upush,没有使用其他的第三方服务,下面的配置,应该就是离线打包upush的必要配置

3.1 libs文件夹android-gif-drawable-release@1.2.17.aar aps-release.aar aps-unipush-release.aar lib.5plus.base-release.aar uniapp-release.aar

3.2 dcloud_properties.xml文件中添加push配置
<features>
<feature name="Push" value="io.dcloud.feature.aps.APSFeatureImpl">
<module name="unipush" value="io.dcloud.feature.unipush.GTPushService"/>
</feature>
</features>
<services>
<service name="push" value="io.dcloud.feature.aps.APSFeatureImpl"/>

</services>  

3.3build.gradle文件
defaultConfig {
applicationId "com.qigu.xxx"
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "1.1.7"
multiDexEnabled true
ndk {
abiFilters 'x86', 'armeabi-v7a'
}
manifestPlaceholders = [
"plus.unipush.appid" : "xxxxxx",
"plus.unipush.appkey" : "xxxx",
"plus.unipush.appsecret": "xxxx",
"apk.applicationId" : "com.qigu.xxx",
"XIAOMI_APP_ID" : "xxxxxx",
"MEIZUPUSH_APPID" : "xxxx",
"HUAWEI_APP_ID" :"xxxxx"

    ]  
}  

dependencies {
implementation fileTree(include: ['.jar'], dir: 'libs')
implementation fileTree(include: ['
.aar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
/uniapp所需库-----------------------开始/
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.alibaba.android:bindingx-core:1.0.3'
implementation 'com.alibaba.android:bindingx_weex_plugin:1.0.3'
implementation 'com.squareup.okhttp:okhttp:2.3.0'
implementation 'com.squareup.okhttp:okhttp-ws:2.3.0'
implementation 'com.alibaba:fastjson:1.1.46.android'
implementation 'com.facebook.fresco:fresco:1.13.0'
implementation "com.facebook.fresco:animated-gif:1.13.0"
/uniapp所需库-----------------------结束/
// 基座需要,必须添加
implementation 'com.github.bumptech.glide:glide:4.9.0'
}

3.4AndroidManifest.xml文件
<!-- Push(推送)-个推 begin -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CALL_PHONE" />

<meta-data
android:name="MIPUSH_APPKEY"
android:value="XM_xxxx" />
<meta-data
android:name="MEIZUPUSH_APPID"
android:value="MZ_xxxxxx" />
<meta-data
android:name="MEIZUPUSH_APPKEY"
android:value="MZ_xxxxxxxx" />
<meta-data
android:name="com.huawei.hms.client.appid"
android:value="xxxxxx" />
<!-- <meta-data
android:name="OPPOPUSHAPPKEY"
android:value="OP
${OPPO_APP_KEY}" />
<meta-data
android:name="OPPOPUSHAPPSECRET"
android:value="OP
${OPPO_APP_SECRET}" />-->
因为oppo的推送需要发布到应用商店 所以没有集成

4.后端采用的是java 直接下载个推的例子修改参数直接运行即可
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.LinkTemplate;
import com.gexin.rp.sdk.template.NotificationTemplate;
import com.gexin.rp.sdk.template.TransmissionTemplate;
import com.gexin.rp.sdk.template.style.Style0;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class AppPush {

// STEP1:获取应用基本信息  
private static String appId = "xxxxx";  
private static String appKey = "xxxx";  
private static String masterSecret = "xxxxx";  
private static String url = "http://sdk.open.api.igexin.com/apiex.htm";  

public static void main(String[] args) throws IOException {  

    IGtPush push = new IGtPush(url, appKey, masterSecret);  

    Style0 style = new Style0();  
    // STEP2:设置推送标题、推送内容  
    style.setTitle("空压机效率超下限告警(30%)");  
    style.setText("您有一条数据告警,请在APP'服务/数据告警'中查看");  
    style.setLogo("../img/push.png");  // 设置推送图标  
    // STEP3:设置响铃、震动等推送效果  
    style.setRing(true);  // 设置响铃  
    style.setVibrate(true);  // 设置震动  

    // STEP4:选择通知模板  
    NotificationTemplate template = new NotificationTemplate();  
    template.setAppId(appId);  
    template.setAppkey(appKey);  
    template.setStyle(style);  
    //TransmissionTemplate template= transmissionTemplateDemo();  

    // 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());  
}  

public static TransmissionTemplate transmissionTemplateDemo() {  
    TransmissionTemplate template = new TransmissionTemplate();  
    template.setAppId(appId);  
    template.setAppkey(appKey);  
    template.setTransmissionType(2);  
    template.setTransmissionContent("请输入需要透传的内容123");  
    return template;  
}  

}

大体上就这些,有些离线打包的基本配置没有写进去,可以参考官方文档,不喜勿喷

该问题目前已经被锁定, 无法添加新回复