<?php
/**
  * @class IM消息通讯
  * @author soul 2019/4/18
  */
class imAction extends baseAction
{
	/**
	  * @method 调取IM接口
	  * @http	post
	  * @param  apiName             string [必填] 接口名称  v4/im_open_login_svc/account_check
	  * @param  params             array [必填] 接口参数  [
			"CheckItem"=>[
				['UserID'=>'soul12']
			]
		]
	  * @author soul
	  * @copyright 2020/6/9
	  * @return
	  */
	public function getApi()
	{
		$OthIm = new OthIm();
		$res = $OthIm->getApi($_POST['apiName'], $_POST['params']);
		LibFc::EchoJson($res);
	}


	/**
	  * @method 生成UserSig
	  * @http	post
	  * @param  token              string [必填] 调用接口凭证 (post|get)
	  * @param  unitag             string [必填] 用户唯一编码
	  * @author soul
	  * @copyright 2019/4/18
	  * @return {"status":true,"data":{"u_id":"149894","u_name":"soul12","u_pay_password":"94c6a8ea51fe1105cc2c5ce8a2420704","u_nickname":"55555555266","u_real_name":"欧昌宇","u_yiparts":"N","u_b2c_worker":"N","u_b2c_shopid":"149894","u_type":"2","u_ul_id":"4","u_email":"472211059@qq.com","u_emil_check":"1","u_mobile":"13535309690","u_mobile_check":"Y","u_weixin_unionid":"ok4Ppv4IBlRwm5pzM45YU6TamVNA","u_weixin_info":{"openid":"obxtFwBqEAQFD8xyJ1QroR7mqk0I","nickname":"蓝宇战车","sex":0,"language":"zh_CN","city":"","province":"","country":"","headimgurl":"http:\/\/thirdwx.qlogo.cn\/mmopen\/vi_32\/I3mx3eDkoPhsaib0dM62bLRhcHOibGS2LQEbxOJ7E6FN3HgySf3pu8gbIIoicIexn8LaNOmb2bOxslkssYsia5ltqA\/132","privilege":[],"unionid":"ok4Ppv4IBlRwm5pzM45YU6TamVNA"},"u_weixin_bd":"Y","u_gzh_bd":"Y","u_integral":"533","u_register_time":"1392825600","u_login_count":"8241","u_login_time":"1555554740","u_error_count":"0","u_error_ltime":"1554885284","u_logo":"Logo\/1078\/100\/c2b6ac864d2772e3.jpg","u_growth":"1160","u_from":null,"ui_period":"2022-04-22 23:59:59","unitag":"lZ0PNT5uRDBonmoxsft6MSMUbzHua2VB0OBxMsShPDVYPyJqdX16MKVQane2VH8wT3d8Mrd5dW3PW3ozl939a0QhZj0=","utag":"c291bDEyQDFjNzU3ZjIyODMxYjk4ZmM1M2QzY2E1N2FmNWNjYzZj","imsig":"eJxNjtFOgzAYRt*FW4xpOwposgtEYthYFjdinDdNpYX9DmgtHXEze-cRwqK35*R8*X6dPNve86JQx9Yye9LSeXSQczdiELK1UII0A*zUscZkMlxrEIxbNjPiX9CJAxvVwLCHEEHEw3SS8keDkYyXdtzDlFKC0C3tpelAtYMgCFNMZgj9SQuNnBJKvYDebnRQDXiVvMZpYsp1vs-9z*diUT4cgtNOxs2L629zLSCq0nCPFwFE7jlrIngiNac0Xbp4QyT63qTLSAX6o-7q1dt7X4WZPIdr30v8eFXN587lCgceVok_"},"code":0}
	  */
	public function getUserSig()
	{
		$OthIm = new OthIm();
		$res = $OthIm->getUserSig($_POST);
		LibFc::EchoJson($res);
	}


	/**
	  * @method 获取管理员的UserSig
	  * @author soul
	  * @copyright 2019/4/18
	  * @return {"status":true,"data":{"imsig":"eJxNjV1PgzAYRv8LtzP6tlBkJl5UNAsZS2SF6IUJqWtXKp-S4tzM-ruEsOjtOTnP8*OkMbvmu107NDa3x046dw44VxPWQjZW77XsR2jaoUJ4NrzrtMi5zd1e-AuMKPNJjQx5ABiwh8gs5Xene5nzvZ32ECEEA1zSL9kb3TajwIAIwi7An7S6lnNCiBcEweVPqxFvnrIwSh5TyVfblrofslgs17UIme8a7W5fT7flclBREH-GqvIpLZJIpeHpeXXMPOaLjBr2dnNYvytVmZrEiyB5eAHWlfWBAi705t45-wJ5JVe6"},"code":0}
	  */
	public function getAdminUserSig()
	{
		$OthIm = new OthIm();
		$res = $OthIm->getAdminUserSig();
		LibFc::EchoJson($res);
	}
	
	/**
	  * @method 导入用户
	  * @http	post
	  * @param  token              string [必填] 调用接口凭证 (post|get)
	  * @param  uids              array [必填] 用户ID数组
	  * @author soul
	  * @copyright 2019/4/18
	  * @return {"status":true,"data":,"code":0}
	  */
	public function importUser()
	{
		$OthIm = new OthIm();
		$res = $OthIm->importUser($_POST['uids']);
		LibFc::EchoJson($res);
	}

	
	/**
	  * @method APP推送消息
	  * @http	post
	  * @param  style  string [必填] 所有客户端:all  自定义:slef  配件商:shop  人脉:renmai  报价者(已填品牌的用户):offer  所有会员:alluser
	  * @param  msg	   string [必填] 推送内容	
	  * @param  title  string [必填] 通知标题
	  * @param  deids array [选填] 设备ID列表 style =slef必填
	  * @param  thi_user string [选填] 发布人
	  * @param  thi_u_id int [选填] 发布人ID
	  * @param  thi_btime int [选填] 定时发送时间
	  * @author soul
	  * @copyright 2019/5/8
	  * @return {"status":true,"data": 推送ID ,"code":0}
	  */
	public function appPush()
	{
		$PjlTs = new PjlTs();
		$othArr = [];
		$othFiledArr = ['thi_user', 'thi_u_id', 'thi_btime', 'thi_style_param'];
		foreach($othFiledArr as $filed)
		{
			if(isset($_POST[$filed])) $othArr[$filed] = $_POST[$filed];
		}
		$res = $PjlTs->push($_POST['style'], $_POST['msg'], $_POST['title'], $_POST['deids'], $othArr);
		LibFc::EchoJson($res);
	}

	/**
	  * @method 取消或者删除推送
	  * @http	get
	  * @param  thi_id	   string [必填] 推送ID
	  * @param  del  string [选填] 默认不删除 true|false
	  * @author soul
	  * @copyright 2019/5/8
	  * @return {"status":true,"data":  ,"code":0}
	  */
	public function closePush()
	{
		$PjlTs = new PjlTs();
		$res = $PjlTs->closePush($_GET['thi_id'], $_GET['del']);
		LibFc::EchoJson($res);
	}

	/**
	  * @method 更新推送的状态
	  * @copyright 2019/5/8
	  * @return {"status":true,"data": true ,"code":0}
	  */
	function checkPushStatus()
	{
		$PjlTs = new PjlTs();
		$res = $PjlTs->checkPushStatus();
		LibFc::EchoJson($res);
	}



	/**
	  * @method 发送系统通知【服务、物流、订单...】
	  * @http	post
	  * @param  uids            string [必填] 接收人ID，多个逗号分隔
	  * @param  msg	            string [必填] 消息内容
	  * @param  msgType	    string [必填] 消息类型 默认im  im:服务通知  order:交易物流  admin:管理员
	  * @author soul
	  * @copyright 2020/12/5
	  * @return {"status":true,"data":[{"ErrorInfo":"","ActionStatus":"OK","ErrorCode":0,"MsgKey":"502870568_36267089_1607156552"}],"code":0,"runtime":235}
	  */
	public function sendImSysNotice()
	{
		$OthIm = new OthIm();
		$res = $OthIm->sendImSysNotice(explode(',', $_POST['uids']), $_POST['msg'], $_POST['msgType']);
		LibFc::EchoJson($res);
	}


	/**
	  * @method 单发单聊消息
	  * @http	post
	  * @param  $fromUid	        int [必填] 发送人ID
	  * @param  $toUid	            int [必填] 接收人ID 
	  * @param  $msg	           string [必填] 消息内容
	  * @author soul
	  * @copyright 2021/3/16
	  * @return {"status":true,"data":{"ErrorInfo":"","ActionStatus":"OK","ErrorCode":0,"MsgKey":"502870568_36267089_1607156552"},"code":0,"runtime":235}
	  */
	public function sendImMsg()
	{
		$OthIm = new OthIm();
		$res = $OthIm->sendImMsg($_POST['fromUid'], $_POST['toUid'], $_POST['msg']);
		LibFc::EchoJson($res);
	}

	/**
	  * @method 单发单聊自定义消息
	  * @http	post
	  * @param  $fromUid	        int [必填] 发送人ID
	  * @param  $toUid	            int [必填] 接收人ID 
	  * @param  $msg	           string [必填] json字符串 {"msg_type":"normal","img_type":"bottom","img":"https://file.paojd.cn/fpjl/zxl/202306/b931b0cba1191318.jpg","link_type":"zx","linkbtn":"立即查看","art_id":4561,"title":"5月产销双增长出口创新高","des":"近期，在经济恢复好转、政策效应持续释放、上年同期基数较低等因素共同作用下，工业主要生产需求指标同比增速回升明显，其中汽车产业5月整体市场表现较4月有所好转。"}
	  * @author soul
	  * @copyright 2021/3/16
	  * @return {"status":true,"data":{"ErrorInfo":"","ActionStatus":"OK","ErrorCode":0,"MsgKey":"502870568_36267089_1607156552"},"code":0,"runtime":235}
	  */
	public function sendImCustomMsg()
	{
		$OthIm = new OthIm();
		$res = $OthIm->sendImCustomMsg($_POST['fromUid'], $_POST['toUid'], json_decode($_POST['msg'], true));
		LibFc::EchoJson($res);
	}

	/**
	  * @method 删除会话
	  * @param  $fromUid	        int [必填] 发送人ID
	  * @param  $toUid	            int [必填] 接收人ID 
	  * @author soul
	  * @copyright 2021/3/16
	  * @return 
	  */
	public function delUseContact()
	{
		$OthIm = new OthIm();
		$res = $OthIm->delUseContact($_POST['fromUid'], $_POST['toUid']);
		LibFc::EchoJson($res);
	}


	/**
	  * @method 设置用户信息
	  * @http	post
	  * @param  uid	            int [必填] 谁的
	  * @param  fileItem	    string [必填] [{"Tag":"Tag_Profile_IM_Nick","Value":"MyNickName"}...]
	  * @author soul
	  * @copyright 2020/12/5
	  * @return {"status":true,"data":{"ActionStatus":"OK","ErrorCode":0,"ErrorInfo":"","ErrorDisplay":""},"code":0,"runtime":323}
	  */
	public function setImUserInfo()
	{
		$OthIm = new OthIm();
		$res = $OthIm->setImUserInfo($_POST['uid'], json_decode($_POST['fileItem'], true));
		LibFc::EchoJson($res);
	}

	/**
	  * @method 将用户变更为活跃用户
	  * @http	post
	  * @param  uids	string [必填] 多个逗号分隔
	  * @param  from	string [选填] 来源 默认manual shop,order,im,purchase,repair,manual(级别最高，不会自动清除)
	  * @author soul
	  * @copyright 2022/8/3
	  * @return {"status":true,"data":'ok',"code":0,"runtime":235}
	  */
	public function addImActUser()
	{
		$OthIm = new OthIm();
		$res = $OthIm->addImActUser(explode(',', $_POST['uids']), $_POST['from']);
		LibFc::EchoJson($res);
	}
}