Search in sources :

Example 1 with AliyunModel

use of org.lpw.ranch.push.aliyun.AliyunModel in project ranch by heisedebaise.

the class AliyunAppSenderImpl method send.

@Override
public boolean send(PushModel push, String receiver, JSONObject args) {
    AliyunModel aliyun = aliyunService.find(push.getAppCode());
    if (aliyun == null)
        return false;
    PushRequest pushRequest = new PushRequest();
    pushRequest.setAppKey(numeric.toLong(aliyun.getAppKey()));
    pushRequest.setTarget("DEVICE");
    pushRequest.setTargetValue(receiver);
    pushRequest.setPushType("NOTICE");
    pushRequest.setDeviceType("ALL");
    pushRequest.setTitle(pushService.parse(PushService.Type.Subject, push.getKey(), push.getSubject(), args));
    pushRequest.setBody(pushService.parse(PushService.Type.Content, push.getKey(), push.getContent(), args));
    pushRequest.setIOSApnsEnv(json.hasTrue(args, "product") ? "PRODUCT" : "DEV");
    pushRequest.setIOSBadge((json.containsKey(args, "badge") ? args.getIntValue("badge") : 1) + 1);
    pushRequest.setIOSMusic(json.containsKey(args, "ios-music") ? args.getString("ios-music") : "default");
    pushRequest.setAndroidMusic(json.containsKey(args, "android-music") ? args.getString("android-music") : "default");
    if (json.containsKey(args, "url")) {
        pushRequest.setAndroidOpenType("URL");
        pushRequest.setAndroidOpenUrl(args.getString("url"));
    } else if (json.containsKey(args, "activity")) {
        pushRequest.setAndroidOpenType("ACTIVITY");
        pushRequest.setAndroidActivity(args.getString("activity"));
    } else
        pushRequest.setAndroidOpenType("APPLICATION");
    try {
        aliyunService.getIAcsClient(aliyun.getAppCode()).getAcsResponse(pushRequest);
        return true;
    } catch (ClientException e) {
        logger.warn(e, "使用阿里云APP推送[{}:{}:{}]时发生异常!", modelHelper.toJson(push), receiver, args);
    }
    return false;
}
Also used : AliyunModel(org.lpw.ranch.push.aliyun.AliyunModel) ClientException(com.aliyuncs.exceptions.ClientException) PushRequest(com.aliyuncs.push.model.v20160801.PushRequest)

Aggregations

ClientException (com.aliyuncs.exceptions.ClientException)1 PushRequest (com.aliyuncs.push.model.v20160801.PushRequest)1 AliyunModel (org.lpw.ranch.push.aliyun.AliyunModel)1