package com.miaxis.test;

import com.alibaba.fastjson.JSONObject;
import com.miaxis.ZzjsApplication;
import com.miaxis.feign.dto.AddTemplate;
import com.miaxis.feign.dto.WxSend;
import com.miaxis.feign.service.IWxSendService;
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 WxTest {

    private String token ="45__6qC8wIAVRtGuk7lz5IlBk678dvuA3383qRGcHJ721sttRJSvxwz6ppCXHIfSFs6AWVdfek21KYvmokK1C3NlUnfYPXm_pKAhm61d9Q6pA1CENOAyIxbX3nJ5NP1knSZUzMLN73pRtGdNXvYWPEgAHARKZ";

    private String token2 ="45_nGtdvZCMg8Kqr74QKw2po6FfKfdUaMYVGOGnnkz1ft1sSF8PzfYTk3hoxjynUx6cgos0WgpGUMU8ymmSw73s3UOkhb__vBJrFUyRLtDzAcQgk34IiRprxcrRo_unC_RftEklW6VM8bc0F7dCXALdAFABEP";

    @Autowired
    private IWxSendService wxSendService;



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


    /**
     * 获取微信小程序token
     */
    @Test
    public void getWxgetTokenService(){
        String result = wxSendService.getAccessToken("client_credential",appid,secret);
        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 getWxSendService(){
        WxSend wxSend = new WxSend();
        wxSend.setAccess_token(token2);
        wxSend.setTouser("oO7PJ5FlradAM7tqw3TM2zvEj4O4");
        wxSend.setTemplate_id("NlZAFJj1p5aHFOg6BBesP7xFAJh5kIZ0kp_YwtJje0g");
        wxSend.setPage("/pages/index/index?active=user");

        JSONObject jsonObject = new JSONObject();
        JSONObject jsonObject1 = new JSONObject();
        JSONObject jsonObject2 = new JSONObject();
        JSONObject jsonObject3 = new JSONObject();
        jsonObject1.put("value","2019年10月1日");
        jsonObject2.put("value","林霖强");
        jsonObject3.put("value","3");
        jsonObject.put("time3",jsonObject1);
        jsonObject.put("name1",jsonObject2);
        jsonObject.put("thing2",jsonObject3);

        wxSend.setData(jsonObject);
        wxSend.setMiniprogram_state("developer");
        wxSend.setLang("zh_CN");

        String result = wxSendService.sendMessage(token,wxSend);
        System.out.println(result);
    }



}
