/**
 * Created by kimber on 2021/9/1
 */

import axios from 'axios';


/**
  * 获取Token
  * @param: {String} appKey
  * @param: {String} appSecret
  *	@example1: getAccessToken('appKey', 'appSecret').then(accessToken => {});
  * @return: 
  * @author: Kimber
  * @updatetime: 
  * @createtime: 2021/9/1
  */
var getAccessToken = function(appKey, appSecret) {
	var dataJson = 'appKey='+appKey+'&appSecret='+appSecret;
	var request = axios.create({});
	request.defaults.headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8';
	return request.post("https://open.ys7.com/api/lapp/token/get", dataJson).then(res=>{
		var data = res.data || {};
		if (data['code'] == '200') {
			return data['data']['accessToken']
		}else{
			return null
		}
	}).catch(err=>{
		console.log(err);
		return err
	})
};

export function getVideoIframe(item){
	var captcha = item.captcha ? item.captcha + '@' :  '';
	var id = item.id;
	return getAccessToken(item.appKey, item.appSecret).then(accessToken => {
		var medaUrl = 'ezopen://'+captcha+'open.ys7.com/'+id+'/1.live&autoplay=1&audio=1&accessToken='+accessToken+'&templete=1';
		return "<iframe src='https://open.ys7.com/ezopen/h5/iframe_se?url="+medaUrl+"' width=\"100%\" height=\"100%\" frameborder=\"no\" border=\"0\" allowfullscreen> </iframe>";
	})
}
