All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.firefly.wechat.utils.CtxUtils Maven / Gradle / Ivy

There is a newer version: 5.0.2
Show newest version
package com.firefly.wechat.utils;

import com.firefly.$;
import com.firefly.server.http2.router.RoutingContext;
import com.firefly.wechat.model.CommonRequest;
import com.firefly.wechat.model.EchoRequest;
import com.firefly.wechat.model.message.MessageRequest;

/**
 * @author Pengtao Qiu
 */
abstract public class CtxUtils {

    @SuppressWarnings("unchecked")
    public static  T toRequest(RoutingContext ctx) {
        if ($.string.hasText(ctx.getParameter("echostr"))) {
            EchoRequest request = new EchoRequest();
            request.setEchostr(ctx.getParameter("echostr"));
            request.setNonce(ctx.getParameter("nonce"));
            request.setSignature(ctx.getParameter("signature"));
            request.setTimestamp(ctx.getParamOpt("timestamp").map(Long::parseLong).orElse(0L));
            return (T) request;
        } else if ($.string.hasText(ctx.getParameter("msg_signature"))) {
            MessageRequest request = new MessageRequest();
            request.setNonce(ctx.getParameter("nonce"));
            request.setSignature(ctx.getParameter("signature"));
            request.setTimestamp(ctx.getParamOpt("timestamp").map(Long::parseLong).orElse(0L));
            request.setMsgSignature(ctx.getParameter("msg_signature"));
            request.setEncryptType(ctx.getParameter("encrypt_type"));
            return (T) request;
        } else {
            return null;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy