/**
 * All rights Reserved, Designed By www.freemud.cn
 *
 * @Title: WeChatServiceTest
 * @Package cn.freemud.service
 * @Description:
 * @author: liming.guo
 * @date: 2018/6/6 16:35
 * @version V1.0
 * @Copyright: 2018 www.freemud.cn Inc. All rights reserved.
 * 注意：本内容仅限于上海非码科技内部传阅，禁止外泄以及用于其他的商业目
 */
package cn.freemud.service;

import cn.freemud.entities.dto.GetWxQrcodeDto;
import cn.freemud.entities.dto.WeChatGetAccessTokenResponseDto;
import cn.freemud.entities.dto.WechatSendMessageDto;
import cn.freemud.service.thirdparty.WeChatClient;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.HashMap;
import java.util.Map;

@RunWith(SpringRunner.class)
@SpringBootTest
@EnableDiscoveryClient
@EnableFeignClients
@EnableAutoConfiguration
public class WeChatServiceTest {

    @Autowired
    private WeChatClient weChatClient;

    @Test
    public void getAccessToken() {
        String appid = "wx2eba2ce69704a6c7";
        String secret = "df050cb30e30b51b8133e06d44d72b9a";
        String grantType = "client_credential";
        WeChatGetAccessTokenResponseDto responseDto = weChatClient.getAccessToken(grantType, appid, secret);
        System.out.println("token==" + responseDto);
    }

    @Test
    public void getWxQrcode() {

        GetWxQrcodeDto getWxQrcodeDto = new GetWxQrcodeDto();
        getWxQrcodeDto.setScene("1036");
        getWxQrcodeDto.setPage("");
        getWxQrcodeDto.setWidth(430);
        String str = weChatClient.getWxacodeunlimit(getWxQrcodeDto);
        System.out.println("wxqrcode==" + str);

    }

    @Test
    public void sendMessageNotice() {
        String accessToken = "17_0NEPvs2YJRxR3bpjOhon2FHEcpn9ue8SBzpyHRFSpyTvjUyvuJIJsKL0i0at-pY7Dou3JWuO6-K6O8aC2cJBS6fjjronQ32p5EYYRfPxHc5z9qAn1q-gDPQl04N7_t0lPnj8HYbIjmwAbWKEPFKdADDCSX";
        String touser = "oORZK5LUxVZyFgqCuzTEHstJOGaI";//ovf0Y40GNyl2qg5QwiZLsB11LeIM  oORZK5LUxVZyFgqCuzTEHstJOGaI
        String templateId = "20kl3uQeiYO7PvrL-z7O6qswiPDSR2sndPT5prC_KiQ";
        String page = "pages/orderDetails?oid=133149780875544839&pageFrom=msg";
        String formId = "wx10182702359930512694f8b01502942951";//ee10bbef7f845522920f36c65bb645ec
        String color = "#FF0000";
        String emphasisKeyword = "keyword1.DATA";
        WechatSendMessageDto.content content = new WechatSendMessageDto.content();
        Map map1 = new HashMap();
        WechatSendMessageDto.content.keyword keyword1 = new WechatSendMessageDto.content.keyword();
        WechatSendMessageDto.content.keyword keyword2 = new WechatSendMessageDto.content.keyword();
        WechatSendMessageDto.content.keyword keyword3 = new WechatSendMessageDto.content.keyword();
        keyword1.setValue("114");
        keyword1.setColor("#173177");
        content.setKeyword1(keyword1);
        keyword2.setValue("肥猫");
        keyword2.setColor("#173177");
        content.setKeyword2(keyword2);
        keyword3.setValue("非码网络科技有限公司");
        keyword3.setColor("#173177");
        content.setKeyword3(keyword3);
        WechatSendMessageDto wechatSendMessageDto = new WechatSendMessageDto();
        wechatSendMessageDto.setTemplate_id(templateId);
        wechatSendMessageDto.setForm_id(formId);
        wechatSendMessageDto.setTouser(touser);
        wechatSendMessageDto.setData(content);
        wechatSendMessageDto.setPage(page);
        wechatSendMessageDto.setEmphasis_keyword(emphasisKeyword);
        String str = weChatClient.sendMessageNotice(accessToken, wechatSendMessageDto);
        System.out.println("getTemplateMessage==" + str);

    }
}
