package com.platform.modules.foreign.service.impl;
/**
* Created by TROY on 2019/2/20.
*/

import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.apache.commons.lang.StringUtils;
import org.apache.lucene.document.Document;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanMap;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.google.common.collect.Maps;
import com.platform.autoconfigure.live.LiveProperties;
import com.platform.common.utils.Constant;
import com.platform.common.utils.ConverterUtils;
import com.platform.common.utils.PageUtils;
import com.platform.common.utils.RedisContants;
import com.platform.common.utils.RedisUtils;
import com.platform.modules.app.entity.LocationEntity;
import com.platform.modules.foreign.entity.AiJiNanUserInfoModel;
import com.platform.modules.foreign.entity.CommentForeignEntity;
import com.platform.modules.foreign.entity.ReporterInterviewProcess;
import com.platform.modules.foreign.entity.SceneForeignEntity;
import com.platform.modules.foreign.entity.SceneStreamForeignEntity;
import com.platform.modules.foreign.utils.AiJinanUtils;
import com.platform.modules.live.constants.SceneConstants;
import com.platform.modules.live.entity.LiveCommentEntity;
import com.platform.modules.live.entity.LiveSceneEntity;
import com.platform.modules.live.entity.LiveSceneLiveInfoEntity;
import com.platform.modules.live.service.LiveChannelService;
import com.platform.modules.live.service.LiveCommentService;
import com.platform.modules.live.service.LiveMultimediaService;
import com.platform.modules.live.service.LiveSceneCountService;
import com.platform.modules.live.service.LiveSceneLiveInfoService;
import com.platform.modules.live.service.LiveSceneService;
import com.platform.modules.live.service.LuceneService;
import com.platform.modules.live.utils.CommentSourceEnum;
import com.platform.modules.live.utils.ForeignProperties;
import com.platform.modules.live.utils.LuceneTypeEnum;
import com.platform.modules.live.utils.PlatformTenantProperties;
import com.platform.modules.live.vo.SceneCountVo;
import com.platform.modules.plm.util.MateriaFileProperties;
import com.platform.modules.plm.util.MaterialUtils;
import com.platform.modules.sensitiveword.service.SensitiveWordService;
import com.platform.modules.sys.entity.SysUserEntity;
import com.platform.modules.sys.entity.SysUserRoleEntity;
import com.platform.modules.sys.service.SysUserRoleService;
import com.platform.modules.sys.service.SysUserService;
import com.platform.modules.weixin.kit.JsSignKit;
import com.platform.modules.weixin.kit.JsSignature;
import com.platform.modules.weixin.kit.StringKit;
import com.platform.modules.weixin.token.JsTicketApi;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

/**
 * @author TROY
 * @version V1.0
 * @ClassName: LiveForeignServiceImpl
 * @Description: 第三方服务数据服务
 * @date 2019/2/20 16:41
 */
@Service("liveForeignService")
public class LiveForeignServiceImpl implements com.platform.modules.foreign.service.LiveForeignService {

	@Autowired
	private LuceneService luceneService;
	@Autowired
	private RedisUtils redisUtils;
	@Autowired
	private LiveSceneService liveSceneService;
	@Autowired
	private LiveCommentService liveCommentService;
	@Autowired
	private ForeignProperties foreignProperties;
	@Autowired
	private SensitiveWordService sensitiveWordService;
	@Autowired
	private AiJinanUtils aiJinanUtils;
	@Autowired
	private LiveChannelService liveChannelService;
	@Autowired
	private LiveSceneCountService liveSceneCountService;
	@Autowired
	private SysUserService sysUserService;
	@Autowired
	private SysUserRoleService sysUserRoleService;
	@Autowired
	private LiveSceneLiveInfoService liveSceneLiveInfoService;
	@Autowired
	private PlatformTenantProperties properties;
	@Autowired
	private MateriaFileProperties materiaFileProperties;
	@Autowired
	private LiveMultimediaService liveMultimediaService;
	@Autowired
	private LiveProperties liveProperties;
	@Override
	public PageUtils getSceneList(Integer cid, Integer source, String title, Integer page, Integer size) {

//		long start = System.currentTimeMillis();
		page = ConverterUtils.parseInt(page);
		size = ConverterUtils.parseInt(size);
		Page<Map<String, Object>> pageStore = new Page<>(page, size);
		List<Map<String, Object>> pageList = new ArrayList<>();
		// 20190401 TROY 增加栏目过滤
		Map<String, String> paramsMap = new HashMap<>();
		if (null!=cid) {
//			paramsMap = new HashMap<>(1);
			paramsMap.put("cid", String.valueOf(cid));
		}
		if (StringUtils.isNotBlank(title)){
			paramsMap.put("title", title);
		}

		paramsMap.put("source", source==null ? null : String.valueOf(source));
		// 20200303_Mxy 对于隐藏的栏目返回空
		if (null == cid){
			return null;
		}else {
			boolean flag = true;
			JSONArray array;
			if (redisUtils.hasKey(RedisContants.CHANNEL_LIST)){
				array = JSONArray.fromObject(redisUtils.get(RedisContants.CHANNEL_LIST));
			}else {
				array = liveChannelService.getRedisCache();
			}

			for (int i = 0; i < array.size(); i++){
				JSONObject object = array.getJSONObject(i);
				if (null != object && null != object.get("id") && cid.equals(object.get("id"))){
					flag = false;
					break;
				}
			}

			if (flag){
				return null;
			}
		}

		List<Document> list = luceneService.search(LuceneTypeEnum.LUCENE_SCENE.getType(), paramsMap, page, size, true);
//		long lucenceTime = System.currentTimeMillis();
//		System.out.println("searchLucene : " + (lucenceTime - start));
		if (null != list && list.size() > 0) {
			Map<String, Object> entity;
			List<String> fieids = new ArrayList<>();
			for (Document doc : list) {
				entity = new HashMap<>();
				String id = doc.get("id");
				entity.put("id", id);
				String thumb = doc.get("thumb");
				entity.put("thumb",
						StringUtils.isNotBlank(thumb)
								? compressImage(MaterialUtils.getMaterialUrl(thumb, foreignProperties.getMediaurl()))
								: "");
				entity.put("title", doc.get("title"));
				entity.put("norb", doc.get("norb"));
				entity.put("time", doc.get("time"));
				entity.put("status", doc.get("status"));
				String path;
				if (StringUtils.isBlank(doc.get("type"))) {
					path = SceneConstants.SceneType.IMAGE.getPath();
				} else {
					path = SceneConstants.SceneType.getPathByKey(Integer.valueOf(doc.get("type")));
				}
				// 20190321 TROY 增加现场类型
				entity.put("type", path);
				entity.put("url", foreignProperties.getWapurl() + "/live/" + path + "/detail/" + id);
				//总浏览量
				entity.put("views", "0");
				// 20190423 TROY 获取多值
				entity.put("cid", doc.getValues("cid"));
				entity.put("cname", doc.getValues("cname"));
				fieids.add(RedisContants.SCENE_COUNT + id);
				pageList.add(entity);
			}
			// redis获取浏览量
			List<Object> viewsList = redisUtils.hmget(RedisContants.SCENE_COUNT, fieids);
			Map<Object, String> viewsMap = new HashMap<>();
			if (null != viewsList && viewsList.size() > 0) {
				Object count;
				for (int i = 0; i < viewsList.size(); i++) {
					count = viewsList.get(i);
					if (null != count) {
						JSONObject countJson = JSONObject.fromObject(count);
						if(!countJson.containsKey("viewsShow") || !countJson.containsKey("sceneId")) continue;
						String sceneId = countJson.getString("sceneId");
						String viewsShow = countJson.getString("viewsShow");
						if (StringUtils.isNotBlank(sceneId) && StringUtils.isNotBlank(viewsShow)) {
							viewsMap.put(sceneId, viewsShow);
						}
					}
//					pageList.get(i).put("views", views);
				}
			}
			for(int i = 0; i < pageList.size(); i++) {
				Object id = pageList.get(i).get("id");
				if(id == null) continue;
				if(viewsMap.containsKey(id))
					pageList.get(i).put("views", viewsMap.get(id));
				else {
					SceneCountVo sceneCountVo = liveSceneCountService.findRedisById(Integer.valueOf(id.toString()));
					if(sceneCountVo != null) {
						pageList.get(i).put("views", sceneCountVo.getViewsShow());
					}
				}
			}
			pageStore.setRecords(pageList);
		}
		long end = System.currentTimeMillis();
//		System.out.println("redisTime : " + (end - lucenceTime));
//		System.out.println("dure :" + (end - start));
		return new PageUtils(pageStore);
	}

	@Override
	public SceneForeignEntity getSceneDetail(Integer id) {
		if (null == id) {
			throw new NullPointerException();
		}
		// 判断Redis是否存在
		String key = SceneConstants.SCENE_REDIS_PREFIX + id;
		boolean hasCache = redisUtils.hasKey(key);
		SceneForeignEntity entity;
		if (hasCache) {
			Map<String, Object> redisObject = redisUtils.hentries(key);
			if (null != redisObject && redisObject.size() > 0) {
				// json序列化字段处理
				Object liveList = redisObject.get("liveList");
				List<SceneStreamForeignEntity> tmpList = null;
				if (liveList instanceof String && StringUtils.isNotBlank((String) liveList)) {
					JSONArray array = JSONArray.fromObject(liveList);
					if (array.size() > 0) {
						tmpList = new ArrayList<>();
						for (Object stream : array.toArray()) {
							tmpList.add((SceneStreamForeignEntity) JSONObject.toBean(JSONObject.fromObject(stream),
									SceneStreamForeignEntity.class));
							// 20200512_Mxy 修改播放地址
//							tmpList.forEach(list -> {
//								if (!"https".equals(StringUtils.substring(list.getPlayUrl(), 0, 5))){
//									StringBuilder sbPlayUrl = new StringBuilder(list.getPlayUrl());
//									list.setPlayUrl(sbPlayUrl.insert(4, "s").toString());
//								}
//								list.setCoverUrl(compressImage(list.getCoverUrl()));
//							});
						}
					}
				}
				entity = new SceneForeignEntity();
				redisObject.remove("liveList");
				BeanMap beanMap = BeanMap.create(entity);
				beanMap.putAll(redisObject);
				entity.setLiveList(tmpList);
				// 20200214_Mxy 设置评论总数
				entity.setComments(liveCommentService.getBySceneId(id).size() + "");
				// 20200316_Mxy 图片压缩
				if (StringUtils.isNotBlank(entity.getTitleImage())){
					if (!entity.getTitleImage().contains("?")){
						entity.setTitleImage(compressImage(entity.getTitleImage()));
					}
				}
				return entity;
			}
		}
		// Redis 不存在将取库数据
		entity = liveSceneService.getForeignScnenInfo(id);
		if (null == entity) {
			throw new NullPointerException();
		}
		// 20200214_Mxy 设置评论总数
		entity.setComments(liveCommentService.getBySceneId(id).size() + "");
		// 10天有效
		redisUtils.hsetall(key, beanToMap(entity), 864000);
		// 20200316_Mxy 图片压缩
		if (StringUtils.isNotBlank(entity.getTitleImage())){
			if (!entity.getTitleImage().contains("?")){
				entity.setTitleImage(compressImage(entity.getTitleImage()));
			}
		}
		// 20200512_Mxy 修改播放地址
		List<SceneStreamForeignEntity> streamList = entity.getLiveList();
		if(streamList!=null && streamList.size()>0){
			streamList.forEach(list -> {
//				if (!"https".equals(StringUtils.substring(list.getPlayUrl(), 0, 5))){
//					StringBuilder sbPlayUrl = new StringBuilder(list.getPlayUrl());
//					list.setPlayUrl(sbPlayUrl.insert(4, "s").toString());
//				}
				list.setCoverUrl(compressImage(list.getCoverUrl()));
			});
		}
		return entity;
	}

	@Override
	public PageUtils getReportList(Integer sceneId, Integer page, Integer size, Boolean reverse) {
		page = ConverterUtils.parseInt(page);
		size = ConverterUtils.parseInt(size);
		Page<Map<String, Object>> pageStore = new Page<>(page, size);
		List<Map<String, Object>> pageList = new ArrayList<>();
		Map<String, String> params = new HashMap<>(1);
		params.put("sceneId", String.valueOf(sceneId));
		if (null==reverse) {
			reverse = true;
		}

		List<Document> list = luceneService.search(LuceneTypeEnum.LUCENE_REPORT.getType(), params, page, size, reverse);
		if (null != list && list.size() > 0) {
			Map<String, Object> entity;
			for (Document doc : list) {
				entity = new HashMap<>();
				entity.put("id", doc.get("id"));
				String mediaUrl = doc.get("mediaUrl");
				entity.put("reportType", doc.get("reportType"));
				entity.put("reportDate", doc.get("reportDate"));
				entity.put("reporterName", doc.get("reporterName"));
				entity.put("content", doc.get("content"));
				entity.put("contentHref", doc.get("contentHref"));
				entity.put("mediaUrl",
						StringUtils.isNotBlank(mediaUrl)
								? MaterialUtils.getMaterialUrl(mediaUrl, foreignProperties.getMediaurl())
								: null);
				String imgList = doc.get("imgList");
				// 20200316_Mxy 图片压缩
				String[] images = handlerPicsList(imgList);
				String[] imageList = null;
				if (null != images){
					imageList = new String[images.length];
					for (int i = 0; i < images.length; i++){
						imageList[i] = compressImage(images[i]);
					}
				}
				entity.put("imgList", imageList);
				// entity.put("imgList", StringUtils.isNotBlank(imgList) ? handlerPicsList(imgList) : null);
				// 20200430_Mxy 现场报道
				entity.put("relatedReport", doc.get("relatedReport"));
				String audioDuration = doc.get("audioDuration");
				if (StringUtils.isNotBlank(audioDuration)){
					entity.put("audioDuration", audioDuration);
				}
				// 20210301_Matt 图片宽高
				if (StringUtils.isNotBlank(doc.get("widthAndHeight"))){
					String[] widthAndHeight = StringUtils.split(doc.get("widthAndHeight"), ",");
					if (widthAndHeight != null && widthAndHeight.length > 0){
						entity.put("widthAndHeight", widthAndHeight);
					}
				}
				pageList.add(entity);
			}
			pageStore.setRecords(pageList);
		}
		return new PageUtils(pageStore);
	}
	
	/**
	 * 获取分页列表数据
	 * 
	 * @param sceneId
	 *            现场ID 必填
	 * @param page
	 *            页数
	 * @param limit
	 *            页面大小
	 * @return
	 */
	@Override
	public List<CommentForeignEntity> getCommentList(Integer sceneId, Integer page, Integer limit) {
		page = ConverterUtils.parseInt(page);
		limit = ConverterUtils.parseInt(limit);
		if (null == sceneId) {
			return new ArrayList<>();
		}
		// 20190321 TROY 增加现场评论状态判断
		SceneForeignEntity scene = null;
		// 20190404 TROY 评论现场不存在异常获取兼容
		try {
			scene = getSceneDetail(sceneId);
		} catch (NullPointerException e) {
			return new ArrayList<>();
		}
		if (null==scene || SceneConstants.AllowComment.NO_COMMENT.getValue().equals(Integer.valueOf(scene.getAllowComment()))) {
			return new ArrayList<>();
		}

		return liveCommentService.queryForeignList(sceneId, page, limit);
	}

	/**
	 * 保存用户评论
	 *
	 * @param sceneId
	 *            场景ID
	 * @param userId
	 *            用户ID
	 * @param headImg
	 *            用户头像
	 * @param userName
	 *            用户姓名
	 * @param text
	 *            评论内容
	 */
	@Override
	public void saveComment(Integer sceneId, Long userId, String headImg, String userName, String text) {
		if (null == sceneId || null == userId) {
			return;
		}

		LiveCommentEntity comment = new LiveCommentEntity();
		comment.setSceneId(sceneId);
		comment.setCreateId(userId);
		comment.setHeadImg(headImg);
		comment.setUserName(userName);
		text = sensitiveWordService.replace(text);
		comment.setText(text);
		liveCommentService.insert(comment);
	}

	@Override
	public void saveComment(Integer sceneId, String token, String text) throws IllegalAccessException {
		if (null == sceneId || StringUtils.isBlank(text)) {
			throw new NullPointerException();
		}
		// 20190321 TROY 增加现场评论状态判断
		SceneForeignEntity scene = getSceneDetail(sceneId);
		if (null==scene || SceneConstants.AllowComment.NO_COMMENT.getValue().equals(Integer.valueOf(scene.getAllowComment()))) {
			throw new NullPointerException();
		}
		LiveCommentEntity comment = new LiveCommentEntity();
		comment.setSceneId(sceneId);
		comment.setSource(CommentSourceEnum.THIRDPLATFORM.getKey());
		if(StringUtils.isNotBlank(token)) {
			AiJiNanUserInfoModel userInfoModel = aiJinanUtils.getUserInfoByToken(token);
			if (userInfoModel == null) {
				throw new IllegalAccessException();
			}
			comment.setCreateId(userInfoModel.getUserId());
			comment.setHeadImg(userInfoModel.getAvatar());
			comment.setUserName(userInfoModel.getUserName());
		}
        comment.setIsRelease(0);
        text = sensitiveWordService.replace(text);
        comment.setText(text);
        comment.setCreateDate(new Date());
        liveCommentService.insert(comment);
        return;
    }
	
	@Override
	public JSONArray channeltList(){

		return liveChannelService.getRedisCache();
	}

	/**
	 * 处理拼接图片资源路径
	 * 
	 * @param imgsStr
	 * @return
	 */
	private String[] handlerPicsList(String imgsStr) {
		String[] imgList = null;
		if (StringUtils.isNotBlank(imgsStr)) {
			String[] imgsArr = imgsStr.split(",");
			if (imgsArr.length > 0) {
				imgList = new String[imgsArr.length];
				for (int j = 0; j < imgsArr.length; j++) {
					imgList[j] = MaterialUtils.getMaterialUrl(imgsArr[j], foreignProperties.getMediaurl());
				}
			}
		}
		return imgList;
	}

	private <T> Map<String, Object> beanToMap(T bean) {
		Map<String, Object> map = Maps.newHashMap();
		if (bean != null) {
			BeanMap beanMap = BeanMap.create(bean);
			Object value;
			for (Object key : beanMap.keySet()) {
				value = beanMap.get(key);
				if (key.equals("liveList")) {
					map.put(key + "", null != value ? JSONArray.fromObject(value).toString() : "");
					continue;
				}
				map.put(key + "", null != value ? String.valueOf(value) : "");
			}
		}
		return map;
	}

	@Override
	public List<ReporterInterviewProcess> findAllReporters() {
		List<SysUserRoleEntity> userRoleEntities = sysUserRoleService.selectList(new EntityWrapper<SysUserRoleEntity>().eq("role_id", 2));
		List<SysUserEntity> userEntities =
				sysUserService.selectList(
						new EntityWrapper<SysUserEntity>()
								.eq(properties.getColumnName(), properties.getManageTenantId())
								.in("user_id",
										userRoleEntities.stream().map(SysUserRoleEntity::getUserId).distinct().toArray()));
		Map<Long, SysUserEntity> reporterMap = userEntities.stream().collect(Collectors.toMap(SysUserEntity::getUserId, e -> e));

		List<LiveSceneLiveInfoEntity> infoEntities =
				liveSceneLiveInfoService.selectList(
						new EntityWrapper<LiveSceneLiveInfoEntity>()
								.eq("info_type", SceneConstants.InfoTypeEnum.REPORTER.getType())
								.eq(properties.getColumnName(), properties.getManageTenantId())
								.gt("user_id", 0));
		List<LiveSceneEntity> sceneEntities =
				liveSceneService.selectList(
						new EntityWrapper<LiveSceneEntity>()
								.eq("scene_state", SceneConstants.SCENE_PROD)
								.eq(properties.getColumnName(), properties.getManageTenantId())
								.in("id",
										infoEntities.stream().map(LiveSceneLiveInfoEntity::getSceneId).distinct().toArray())
								.orderBy("live_start", false));
		Map<Integer, LiveSceneEntity> sceneMap = sceneEntities.stream().collect(Collectors.toMap(LiveSceneEntity::getId, e -> e));
		List<ReporterInterviewProcess.InterviewProcess> interviewProcesses =
				infoEntities.stream().filter(e ->
						reporterMap.containsKey(Long.parseLong(e.getUserId() + "")) && sceneMap.containsKey(e.getSceneId()))
						.map(e -> {
							ReporterInterviewProcess.InterviewProcess process = new ReporterInterviewProcess.InterviewProcess();
							process.setReporterId(Long.parseLong(e.getUserId() + ""));
							LiveSceneEntity liveSceneEntity = sceneMap.get(e.getSceneId());
							process.setAddr(liveSceneEntity.getLivePosition());
							process.setInterviewTitle(liveSceneEntity.getTitle());
							process.setState(liveSceneEntity.getLiveState());
							Date liveStart = liveSceneEntity.getLiveStart();
							ZoneId zoneId = ZoneId.systemDefault();
							process.setStartDate(DateTimeFormatter.ofPattern("yyyy-MM-dd").format(liveStart.toInstant().atZone(zoneId).toLocalDateTime()));
							return process;
						}).sorted(Comparator.comparing(ReporterInterviewProcess.InterviewProcess::getStartDate).reversed()).collect(Collectors.toList());

		Map<Long, List<ReporterInterviewProcess.InterviewProcess>> interviewProcessMap =
				interviewProcesses.stream().collect(Collectors.groupingBy(ReporterInterviewProcess.InterviewProcess::getReporterId));
		List<ReporterInterviewProcess> result = userEntities.stream().map(e -> {
			ReporterInterviewProcess data = new ReporterInterviewProcess();
			if (interviewProcessMap.containsKey(e.getUserId()))
				data.setInterviewProcesses(interviewProcessMap.get(e.getUserId()).stream().limit(3).collect(Collectors.toList()));
			else
				data.setInterviewProcesses(new ArrayList<>());
			data.setReportId(e.getUserId());
			data.setReporterName(e.getRealname());
			if (StringUtils.isNotBlank(e.getUserImg()))
				data.setReporterImg(MaterialUtils.getMaterialUrl(e.getUserImg(), materiaFileProperties.getBasePath()));
			if (redisUtils.hexists(Constant.REDIS_LOCATION_REPORT, e.getUserId().toString())) {
				data.setPosition(redisUtils.hget(Constant.REDIS_LOCATION_REPORT, e.getUserId().toString(), LocationEntity.class));
			}

			//20200106 weiyan 大屏记者状态
			data.setStatus(getReporterOnLineRedisById(e.getUserId()));
			//20200528 记者推流状态
			data.setIsPush(getReporterPushStateRedisById(e.getUserId()));
			return data;
		}).collect(Collectors.toList());
		return result;
	}

	//20200106 weiyan 记者状态查询
	public Integer getReporterOnLineRedisById(Long userId){
		String key = RedisContants.REPORTER_ONLINE + userId;
		Integer status = redisUtils.get(key, Integer.class);
		return status==null ? 0 : status;
	}

	//20200528 记者是否推流
	private Integer getReporterPushStateRedisById(Long userId){
		Integer loginState = redisUtils.hget(RedisContants.REPORTER_PUSH_STATE, userId.toString(), Integer.class);
		return null == loginState ? 0 : loginState;
	}

	/**
	 * 20200316_Mxy 图片压缩
	 *
	 * @param sourceUrl 图片地址
	 * */
	private String compressImage(String sourceUrl){
		// 返回拼接压缩后地址
		return sourceUrl + liveProperties.getCompressImage().getGeometricFormat();
	}
	
	/**
	 * 获取微信JS验证
	 */
	public JSONObject getWeixinJsApiTicket(String url){
		JSONObject jsonObject = new JSONObject();
		
    	JsTicketApi jsTicketApi = new JsTicketApi(liveProperties.getWeixin().getAppId(), liveProperties.getWeixin().getAppSecret(), redisUtils);
    	
		String timeStamp = System.currentTimeMillis() / 1000 + "";
		String nonceStr = StringKit.getRandomString(16);
		
		String jsapi_ticket = jsTicketApi.getJsTicketFromRedis();
		if(StringUtils.isBlank(jsapi_ticket)){
			return null;
		}
		JsSignature signature = new JsSignature(nonceStr, jsapi_ticket, timeStamp, url);
		
		String sign = JsSignKit.sign(signature);
		jsonObject.put("appid", liveProperties.getWeixin().getAppId());
		jsonObject.put("timeStamp", timeStamp);
		jsonObject.put("nonceStr", nonceStr);
		jsonObject.put("sign", sign);
		jsonObject.put("url", url);
		
		return jsonObject;
	}
}
