package com.zhiqiyun;

import com.alibaba.fastjson.JSON;
import com.dliyun.AlgorithmType;
import com.dliyun.ClientException;
import com.dliyun.DefaultClient;
import com.dliyun.Response;
import org.junit.Test;

import java.util.*;

public class TestSdk {
	private DefaultClient getClient() {
		return new DefaultClient(
				"http://127.0.0.1:9800/router",
				"220228000020",
				"MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCSTihNSHP5mqzMxkqxeEv150GWUcfdNy9eoD9wWhWO5re59vi8ownmfpcKOSHhqM09W+/jwC5xbqhYJN2kbCMWTyBHJ1BaoldX736aOPCmo0octyiq2N3Xx5JFnBh5asXdEO12lrOXGNqcwwq6iDuw2Na3H4u7p3QEIz6LKLcGJQIDAQAB",
				AlgorithmType.RSA
		);
	}

	@Test
	public void testlogin() throws ClientException {
		Map<String, Object> dataMap = new HashMap<>();
		dataMap.put("userName", "18812345678");
		dataMap.put("password", "admin");
		Response<Map<String, Object>> response = this.getClient().execute("oauth2.login", "1.0.0", dataMap);
		System.out.println(JSON.toJSONString(response));
	}

	@Test
	public void testUpdatePassword() throws ClientException {
		Map<String, Object> dataMap = new HashMap<>();
		dataMap.put("accessToken", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0ZW5hbnRfaWQiOm51bGwsInVzZXJfbmFtZSI6InN0amR5ZGF5b3UiLCJyZWFsX25hbWUiOiI2NTQzMjEiLCJhdmF0YXIiOiIiLCJjbGllbnRfaWQiOiJzYWJlciIsInJvbGVfbmFtZSI6IiIsImxpY2Vuc2UiOiJwb3dlcmVkIGJ5IGJsYWRleCIsImFjY291bnRfaWQiOiIxNTAwMTAwODE3ODMyMzIxMDI2IiwicG9zdF9pZCI6IiIsInVzZXJfaWQiOiIiLCJyb2xlX2lkIjoiIiwic2NvcGUiOlsiYWxsIl0sIm5pY2tfbmFtZSI6IjEyMzQ1NiIsIm9hdXRoX2lkIjoiIiwiZGV0YWlsIjpudWxsLCJleHAiOjE2NDcwMTcyNTMsImRlcHRfaWQiOiIiLCJqdGkiOiI5N2NhZTAxMS0yYjcwLTRlMzQtYWM2ZC02YWM4ZWY1YWIyMzEiLCJhY2NvdW50Ijoic3RqZHlkYXlvdSJ9.nvXxZ_qlfLYFsL3WEwi5J26nGv7u_PHPnchEHNKs384");
		dataMap.put("oldPassword", "654321");
		dataMap.put("newPassword", "123456");
		Response<Map<String, Object>> response = this.getClient().execute("oauth2.update.password", "1.0.0", dataMap);
		System.out.println(JSON.toJSONString(response));
	}

	@Test
	public void testUpdateInfo() throws ClientException {

		Map<String, Object> dataMap = new HashMap<>();
		dataMap.put("accessToken", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0ZW5hbnRfaWQiOm51bGwsInVzZXJfbmFtZSI6InN0amR5ZGF5b3UiLCJyZWFsX25hbWUiOiI2NTQzMjEiLCJhdmF0YXIiOiIiLCJjbGllbnRfaWQiOiJzYWJlciIsInJvbGVfbmFtZSI6IiIsImxpY2Vuc2UiOiJwb3dlcmVkIGJ5IGJsYWRleCIsImFjY291bnRfaWQiOiIxNTAwMTAwODE3ODMyMzIxMDI2IiwicG9zdF9pZCI6IiIsInVzZXJfaWQiOiIiLCJyb2xlX2lkIjoiIiwic2NvcGUiOlsiYWxsIl0sIm5pY2tfbmFtZSI6IjEyMzQ1NiIsIm9hdXRoX2lkIjoiIiwiZGV0YWlsIjpudWxsLCJleHAiOjE2NDcwMTcyNTMsImRlcHRfaWQiOiIiLCJqdGkiOiI5N2NhZTAxMS0yYjcwLTRlMzQtYWM2ZC02YWM4ZWY1YWIyMzEiLCJhY2NvdW50Ijoic3RqZHlkYXlvdSJ9.nvXxZ_qlfLYFsL3WEwi5J26nGv7u_PHPnchEHNKs384");
		dataMap.put("name", "123456");
		dataMap.put("realName", "654321");
		dataMap.put("sex", "1");
		dataMap.put("email", "stjdydayou@163.com");
		dataMap.put("phone", "18073113117");
		Response<Map<String, Object>> response = this.getClient().execute("oauth2.update.info", "1.0.0", dataMap);
		System.out.println(JSON.toJSONString(response));
	}

	@Test
	public void testWechatLogin() throws ClientException {

		Map<String, Object> dataMap = new HashMap<>();
		dataMap.put("source", "WECHAT_MP");
		dataMap.put("uuid", "wxc01ea0423e91d9e0");
		dataMap.put("name", "wxc01ea0423e91d9e0");
		dataMap.put("realName", "wxc01ea0423e91d9e0");
		Response<Map<String, Object>> response = this.getClient().execute("oauth2.wechat.login", "1.0.0", dataMap);
		System.out.println(JSON.toJSONString(response));
	}


	@Test
	public void socialSubmit() throws ClientException {
		Map<String, Object> dataMap = new HashMap<>();
		dataMap.put("accessToken", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0ZW5hbnRfaWQiOm51bGwsInVzZXJfbmFtZSI6IjE4ODEyMzQ1Njc4IiwicmVhbF9uYW1lIjoiYWRtaW4iLCJhdmF0YXIiOiIiLCJjbGllbnRfaWQiOiJzYWJlciIsInJvbGVfbmFtZSI6IiIsImxpY2Vuc2UiOiJwb3dlcmVkIGJ5IGJsYWRleCIsImFjY291bnRfaWQiOiIxNTAyMTg0MDY4OTg3NDMyOTYyIiwicG9zdF9pZCI6IiIsInVzZXJfaWQiOiIiLCJyb2xlX2lkIjoiIiwic2NvcGUiOlsiYWxsIl0sIm5pY2tfbmFtZSI6ImFkbWluIiwib2F1dGhfaWQiOiIiLCJkZXRhaWwiOm51bGwsImV4cCI6MTY0NzAyMDI0NCwiZGVwdF9pZCI6IiIsImp0aSI6IjMwNWM0M2MwLWQ1NTAtNDhiMi05Yjk4LTkzNTM2NDllMGI1NyIsImFjY291bnQiOiIxODgxMjM0NTY3OCJ9.wtdQahB8Fn_lixfoDbYyLZ-HWB0p6H8T3TRV3timWaQ");
		dataMap.put("account", "zxcc");
		dataMap.put("password", "123456");
		dataMap.put("name", "Jtoms");
		dataMap.put("realName", "Jtoms.Shen");
		dataMap.put("sex", "1");
		dataMap.put("email", "stjdydayou@163.com");
		dataMap.put("phone", "18073113117");
		Response<Map<String, Object>> response = this.getClient().execute("oauth2.social.submit", "1.0.0", dataMap);
		System.out.println(JSON.toJSONString(response));
	}

	@Test
	public void socialUpdate() throws ClientException {
		Map<String, Object> dataMap = new HashMap<>();
		dataMap.put("accessToken", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0ZW5hbnRfaWQiOm51bGwsInVzZXJfbmFtZSI6IjE4ODEyMzQ1Njc4IiwicmVhbF9uYW1lIjoiYWRtaW4iLCJhdmF0YXIiOiIiLCJjbGllbnRfaWQiOiJzYWJlciIsInJvbGVfbmFtZSI6IiIsImxpY2Vuc2UiOiJwb3dlcmVkIGJ5IGJsYWRleCIsImFjY291bnRfaWQiOiIxNTAyMTg0MDY4OTg3NDMyOTYyIiwicG9zdF9pZCI6IiIsInVzZXJfaWQiOiIiLCJyb2xlX2lkIjoiIiwic2NvcGUiOlsiYWxsIl0sIm5pY2tfbmFtZSI6ImFkbWluIiwib2F1dGhfaWQiOiIiLCJkZXRhaWwiOm51bGwsImV4cCI6MTY0NzAyMDI0NCwiZGVwdF9pZCI6IiIsImp0aSI6IjMwNWM0M2MwLWQ1NTAtNDhiMi05Yjk4LTkzNTM2NDllMGI1NyIsImFjY291bnQiOiIxODgxMjM0NTY3OCJ9.wtdQahB8Fn_lixfoDbYyLZ-HWB0p6H8T3TRV3timWaQ");
		dataMap.put("id", "1502187187179827201");
		dataMap.put("name", "Jtoms1");
		dataMap.put("realName", "Jtoms2");
		dataMap.put("sex", "2");
		dataMap.put("email", "stjdydayou@1631.com");
		dataMap.put("phone", "18073113118");
		Response<Map<String, Object>> response = this.getClient().execute("oauth2.social.update", "1.0.0", dataMap);
		System.out.println(JSON.toJSONString(response));
	}

	@Test
	public void socialRemove() throws ClientException {
		Map<String, Object> dataMap = new HashMap<>();
		dataMap.put("accessToken", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0ZW5hbnRfaWQiOiIxMDQ3ODQiLCJ1c2VyX25hbWUiOiIxMzY2NjY2NjY2NiIsInJlYWxfbmFtZSI6ImFkbWluIiwiYXZhdGFyIjoiIiwiYXV0aG9yaXRpZXMiOlsiYWRtaW4iXSwiY2xpZW50X2lkIjoic2FiZXIiLCJyb2xlX25hbWUiOiJhZG1pbiIsImxpY2Vuc2UiOiJwb3dlcmVkIGJ5IGJsYWRleCIsImFjY291bnRfaWQiOiIxNDg0MTI3ODYwMzI5NDcyMDAxIiwicG9zdF9pZCI6IjE0ODQxMjc4NTk2MzcxNTc4ODkiLCJ1c2VyX2lkIjoiMTQ4NDEyNzg2MDI0MTM5MTYxOCIsInJvbGVfaWQiOiIxNDg0MTI3ODU3MzUxMjYyMjEwIiwic2NvcGUiOlsiYWxsIl0sIm5pY2tfbmFtZSI6bnVsbCwib2F1dGhfaWQiOiIiLCJkZXRhaWwiOnsidHlwZSI6IndlYiJ9LCJleHAiOjE2NDcyODczODQsImRlcHRfaWQiOiIxNDg0MTI3ODU5NjIwMzgwNjc0IiwianRpIjoiMzgzZTYyZTItY2JiYS00MzBiLWIwMmUtODE1MmE4Yzg4MGE4IiwiYWNjb3VudCI6IjEzNjY2NjY2NjY2In0.JBjhpDVrmzdSyJTU2ebBtNP-6qhrAuPgXLfUztPAYe4");
		dataMap.put("id", "1253564710732921783");
		Response<Map<String, Object>> response = this.getClient().execute("oauth2.social.remove", "1.0.0", dataMap);
		System.out.println(JSON.toJSONString(response));
	}

	@Test
	public void getImageCaptcha() throws ClientException {
		Map<String, Object> dataMap = new HashMap<>();
		Response<Map<String, Object>> response = this.getClient().execute("oauth2.get.image.captcha", "1.0.0", dataMap);
		System.out.println(JSON.toJSONString(response));
	}

	@Test
	public void sendPhoneValidateCode() throws ClientException {
		Map<String, Object> dataMap = new HashMap<>();
		dataMap.put("phone", "18073113118");
		dataMap.put("captchaCode", "kan4x");
		dataMap.put("captchaKey", "81e50122a3f2617c00bf92205609329b");
		Response<Map<String, Object>> response = this.getClient().execute("oauth2.send.phone.validate.code", "1.0.0", dataMap);
		System.out.println(JSON.toJSONString(response));
	}

	@Test
	public void sendPhoneLogin() throws ClientException {
		Map<String, Object> dataMap = new HashMap<>();
		dataMap.put("phone", "18073113118");
		dataMap.put("code", "271923");
		dataMap.put("id", "0ddd1226f73fa454566b36d69ea1abe6");
		Response<Map<String, Object>> response = this.getClient().execute("oauth2.phone.login", "1.0.0", dataMap);
		System.out.println(JSON.toJSONString(response));
	}

	@Test
	public void startSpider() throws ClientException {
		Map<String, Object> dataMap = new HashMap<>();
		dataMap.put("ids", Collections.singletonList("220315171635"));
		Response<Map<String, Object>> response = this.getClient().execute("sentiment.spider.event.startSpider", "1.0.0", dataMap);
		System.out.println(JSON.toJSONString(response));
	}

	@Test
	public void sendForgetPassword() throws ClientException {
		Map<String, Object> dataMap = new HashMap<>();
		dataMap.put("phone", "18073113118");
		dataMap.put("code", "457100");
		dataMap.put("id", "c4fb91adcf9bd8683aab344c3568e5f8");
		dataMap.put("password", "123456");
		Response<Map<String, Object>> response = this.getClient().execute("oauth2.forget.password", "1.0.0", dataMap);
		System.out.println(JSON.toJSONString(response));
	}

	@Test
	public void saveComplaintInfo() throws ClientException {
		Map<String, Object> dataMap = new HashMap<>();
		dataMap.put("orgId", "10000");
		dataMap.put("bigType", "1");
		dataMap.put("type", "1");
		dataMap.put("channel", "channel");
		dataMap.put("litpics", new ArrayList<>());
		dataMap.put("content", "content");
		Response<Map<String, Object>> response = this.getClient().execute("save.complaint.info", "1.0.0", dataMap);
		System.out.println(JSON.toJSONString(response));
	}
}
