package com.github.zouzhberk.controller.we;


import com.github.zouzhberk.essence.rxwe.RxWe;
import com.github.zouzhberk.essence.rxwe.domain.TokenEntity;
import com.github.zouzhberk.essence.rxwe.features.BaseSupportApi;
import com.github.zouzhberk.utils.MPConst;
import com.github.zouzhberk.utils.WeUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by berk on 3/12/16.
 */
@RequestMapping("/")
@RestController
public class WeMessageController {

    @RequestMapping(method = RequestMethod.GET)
    public String validateSignature(@RequestParam("signature") String signature, @RequestParam("timestamp") long
            timestamp, @RequestParam("nonce") String nonce, @RequestParam("echostr") String echostr) {

        RxWe rxWe = RxWe.Builder.builder().build();
        TokenEntity tokenEntity = rxWe.create(BaseSupportApi.class).getToken(MPConst.GRANT_TYPE, MPConst.APP_ID,
                MPConst.SECRET_ID).toBlocking().first();
        String newsigature = WeUtils.generateSignature(MPConst.TOKEN, timestamp + "", nonce);
        System.out.println(echostr);
        if (newsigature.equals(signature)) {
            return echostr;
        }

        return "error";
    }

    @RequestMapping(value = "test", method = RequestMethod.GET)
    public String testapi(@RequestParam("signature") String signature) {
        return "hello world " + signature;
    }

}

@@ -43,182 +43,8 @@
 ;%0A%0A%0A
-import com.github.zouzhberk.essence.rxwe.RxWe;%0Aimport com.github.zouzhberk.essence.rxwe.domain.TokenEntity;%0Aimport com.github.zouzhberk.essence.rxwe.features.BaseSupportApi;%0A
 impo
@@ -748,24 +748,26 @@
 echostr) %7B%0A%0A
+//
         RxWe
@@ -802,24 +802,26 @@
 ().build();%0A
+//
         Toke
@@ -921,16 +921,18 @@
 APP_ID,%0A
+//
         

update .