package com.miaxis.test;

import com.alibaba.fastjson.JSONObject;
import com.miaxis.ZzjsApplication;
import com.miaxis.feign.dto.WxGzhMini;
import com.miaxis.feign.dto.WxGzhSend;
import com.miaxis.feign.dto.WxSend;
import com.miaxis.feign.service.IWxGzhService;
import com.miaxis.feign.service.IWxSendService;
import com.miaxis.feign.service.IWxService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

@SpringBootTest(classes = ZzjsApplication.class)
@RunWith(SpringRunner.class)
public class WxGzhTest {


    @Autowired
    private IWxSendService wxSendService;

    private String token = "45_Njoe3zgvKCg8xoD2BZWcfi2BjkibZcR7SfgtgiTr-GsJIc6AlAuYkB-Us211vA5rffZEtf-6eFrjVE9BXz2j2hLMl5X3C9RR6vApEDtR_Xi5hza5JFY1jBt4PQdAJZLPxHkijYGFnMqxWy7mURLhABAEBV";
    private String token2 = "45_u4-UR-tGJPQ3B_ZMuGX1BaxQH_eRCJUu7QkFQv0AuHeDvAG8SUYR1tlfhp93SeNwX_xEBYBjJAKuy54DHZEZEl670bIDlLZyDfwOAtKQVgpohTJLJxs948lGRhGgQVgsbB0cYt1toCbbxM-TCIPjABAYEL";

    @Value("${gzh.appid}")
    private String appid;
    @Value("${gzh.secret}")
    private String secret;


    @Test
    public void getWxgetTokenService(){
        String result = wxSendService.getAccessToken("client_credential",appid,secret);

        System.out.println(result);
        JSONObject json = JSONObject.parseObject(result);
        String accessToken = json.get("access_token").toString();
        String expiresIn = json.get("expires_in").toString();
        System.out.println(accessToken);
        System.out.println(expiresIn);
    }

    @Test
    public void getWxGzhService(){
        WxGzhSend gzhSend = new WxGzhSend();
        gzhSend.setTouser("oYiEFwrmR6tquoFPXL2KlwT8WfWU");
        gzhSend.setTemplate_id("3TKF3q46VuxrM2lsCOhs0S4-uH6UeND2FN-rJ4DUFYg");
        gzhSend.setUrl("https://www.baidu.com/");
        WxGzhMini wxGzhMini = new WxGzhMini();
        wxGzhMini.setAppid("wx8f43db501343feab");
        wxGzhMini.setPagepath("/pages/index/index");
        gzhSend.setMiniprogram(wxGzhMini);


        JSONObject jsonObject = new JSONObject();
        JSONObject jsonObject1 = new JSONObject();
        JSONObject jsonObject2 = new JSONObject();
        JSONObject jsonObject3 = new JSONObject();
        JSONObject jsonObject4 = new JSONObject();
        jsonObject1.put("value","恭喜你购买成功！");
        jsonObject1.put("color","#173177");
        jsonObject2.put("value","巧克力");
        jsonObject3.put("value","39.8元");
        jsonObject4.put("value","这东西不错");

        jsonObject.put("first",jsonObject1);
        jsonObject.put("keyword1",jsonObject2);
        jsonObject.put("keyword2",jsonObject3);
        jsonObject.put("remark",jsonObject4);
        gzhSend.setData(jsonObject);

        String result = wxSendService.sendGzhMessage(token2,gzhSend);
        System.out.println(result);
    }

}
