load->_model('Model_shop','shop'); $this->load->_model('Model_fullorder','fullorder'); $this->load->_model('Model_fullordertt','fullordertt'); $this->load->_model('Model_fullordersmt','fullordersmt'); $this->load->_model('Model_fullorderxw','fullorderxw'); $this->load->_model('Model_fullorder_2020','fullorder2020'); $this->load->_model('Model_fullordersmt_2020','fullordersmt2020'); $this->load->_model('Model_customersmt','customersmt'); $this->load->_model('Model_country','country'); $this->load->_model('Model_hl','hl'); $this->load->_model('Model_is','is'); $this->load->_model('Model_kdniao','kdniao'); $this->load->_model('Model_typeclass','typeclass'); $this->load->_model('Model_warehouse','warehouse'); $this->load->_model('Model_fullorderexcel','fullorderexcel'); $this->load->_model('Model_dhl','dhl'); $this->load->_model('Model_usps','usps'); $this->load->_model('Model_dhltest','dhltest'); $this->load->_model('Model_customer','customer'); $this->load->_model('Model_express','express'); $this->load->_model('Model_notice','notice'); $this->load->_model('Model_whlabel','whlabel'); $this->load->_model('Model_productdescribe','productdescribe'); $this->load->_model('Model_ljg','ljg'); $this->load->_model('Model_commodityread','commodityread'); $this->load->_model('Model_service','service'); $this->load->_model('Model_fedex','fedex'); $this->load->_model('Model_commodity','commodity'); $this->load->_model('Model_fullordersmtorder','fullordersmtorder'); $this->load->_model('Model_ali','ali'); $this->load->_model('Model_fullordersmthb','fullordersmthb'); $this->load->_model('Model_fullordersmtbf','fullordersmtbf'); $this->load->_model('Model_taxzhengzhou','taxzhengzhou'); $this->load->_model('Model_taxshanghai','taxshanghai'); $this->load->_model('Model_excel','excel'); $this->load->_model('Model_ups','ups'); $this->load->_model('Model_dpd','dpd'); $this->load->_model('Model_dpdold','dpdold'); $this->load->_model('Model_dpd_IOSS','dpd_IOSS'); $this->load->_model('Model_dpdxw','dpdxw'); $this->load->_model('Model_cne','cne'); $this->load->_model('Model_outbound','outbound'); $this->load->_model('Model_api','api'); $this->load->_model('Model_dhlhz','dhlhz'); $this->load->_model('Model_apismt','apismt'); $this->load->_model('Model_specialstock','specialstock'); $this->load->_model('Model_systemwigsout','systemwigsout'); $this->load->_model('Model_purchaseorder','purchaseorder'); $this->load->_model('Model_returns','returns'); $this->load->_model('Model_whlabellabel','whlabellabel'); $this->load->_model('Model_whlabelbarcode','whlabelbarcode'); $this->load->_model('Model_tjadd','tjadd'); $this->load->_model('Model_stafflist','stafflist'); $this->load->_model('Model_paypal','paypal'); $this->load->_model('Model_warehousefactory','warehousefactory'); $this->load->_model('Model_commodityread_del','commodityreaddel'); $this->load->_model('Model_als','als'); $this->load->_model('Model_allocation','allocation'); $this->load->_model('Model_17track','17track'); $this->load->_model('Model_hualei','hualei'); $this->load->_model('Model_ck','ck'); $this->load->_model('Model_colour','colour'); $this->load->_model('Model_color','color'); $this->load->_model('Model_emaildata','emaildata'); $this->load->_model('Model_wigprint','wigprint'); $this->load->_model('Model_weight','weight'); $this->load->_model('Model_whlabeltransport','whlabeltransport'); $this->load->_model('Model_pay','pay'); $this->load->_model('Model_orderurl','orderurl'); $this->load->_model('Model_classid','classid'); $this->load->_model('Model_apiyy','apiyy'); $this->load->_model('Model_purchase','purchase'); $this->load->_model('Model_apitt','apitt'); $this->load->_model('Model_whlabel_bh','whlabel_bh'); $this->load->_model('Model_whlabel_fc','whlabel_fc'); $this->load->_model('Model_systemtransfer','systemtransfer'); $this->load->_model('Model_systemtransfer_del','systemtransfer_del'); $this->load->_model('Model_power','power'); $this->load->_model('Model_fullorderexcel','fullorderexcel'); $this->load->_model('Model_fullorderexcelclassid','fullorderexcelclassid'); $this->load->_model('Model_awlgx','awlgx'); $this->load->_model('Model_shopsku','shopsku'); } //定义方法的调用规则 获取URI第二段值 public function _remap($arg,$arg_array) { if($arg == 'a') { $this->_a($arg_array); } else if($arg == 'ac') { $this->_ac($arg_array); } else if($arg == 'x') { $this->_x($arg_array); } else if($arg == 'x2') { $this->_x2($arg_array); } else if($arg == 'x3') { $this->_x3($arg_array); } else if($arg == 'xx') { $this->_xx($arg_array); } else if($arg == 'Token') { $this->_sku($arg_array); } } public function _a() { // 您的邮箱地址和密码 $username = 'service@asteriahair.com'; $password = '1026@asas.$1026'; // 阿里云邮箱的 IMAP 服务器地址和端口号 $hostname = '{imap.mxhichina.com:993/imap/ssl}INBOX'; // 尝试连接到阿里云邮箱的 IMAP 服务器 $inbox = imap_open($hostname, $username, $password); // 获取邮箱中的邮件数量 $total_emails = imap_num_msg($inbox); $data = array(); // 读取前10封邮件的内容 for ($i = 1; $i <= min($total_emails, 2); $i++) { // 获取邮件头信息 $header = imap_header($inbox, $i); // 获取邮件内容 $body = imap_fetchbody($inbox, $i, 1); // 参数2表示获取邮件的第1个部分,通常为邮件正文 // 获取邮件编码类型 $encoding = isset($header->encoding) ? $header->encoding : null; // 如果邮件内容是base64编码的,则解码 if ($encoding == 3) { $body = base64_decode($body); } $uid = imap_uid($inbox, $i); $data[] = array( "id"=>$header->from, "UID:"=>$uid, "标题:"=>$header->subject, "发送人:"=>$header->fromaddress, "时间:"=>$header->MailDate, "内容:"=>$body); // nl2br() 函数用于将换行符转换为 HTML 的换行标签 } // 关闭连接 imap_close($inbox); echo "
";
	print_r($data);

exit;
		$shop = $this->shop->read(35);
		$url = 'https://open-api.tiktokglobalshop.com';
		$link = '/authorization/202309/shops';
		$time = time();
		$queryParams = array();
		//$queryParams['access_token'] = $shop['token'];
		$queryParams['app_key'] = $shop['app_key'];
		//$queryParams['shop_id'] = $shop['codeid'];
		$queryParams['timestamp'] = $time;
		//$queryParams['version'] = '202309';
		$link .= '?' . http_build_query($queryParams);
		$sign = $this->apitt->sign($link,$shop['token'],$shop['app_secret']);
		$url .= $link.'&sign='.$sign;
		$headers = array('x-tts-access-token:'.$shop['token']);
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
		curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
		$res = curl_exec($ch);
		curl_close($ch);
		$res = json_decode($res,true);
		echo "
";
		print_r($res);
		exit;
		$d = $this->fullordertt->get_number("TT-WK-40402-169");
		$shop = $this->shop->read($d['shop']);
		$url = 'https://open-api.tiktokglobalshop.com';
		$link = '/customer_service/202309/conversations';
		$time = time();
		$post['buyer_user_id'] = $d['user_id'];
		$queryParams['shop_cipher'] =$shop['shop_cipher'];
		//$queryParams['shop_id'] =$shop['codeid'];
		$queryParams['app_key'] =$shop['app_key'];
		$queryParams['timestamp'] =$time;
		$link .= '?'.http_build_query($queryParams);
		$sign = $this->sign($link,$shop['app_secret'],$post);
		$url .= $link.'&sign='.$sign;
		$headers = array('Content-Type: application/json','x-tts-access-token:'.$shop['token']);
		$res = $this->su_curl($post,$url,$headers);
		$res = json_decode($res,true);
		echo "
";
		print_r($res);
		exit;
		
		$data = '{"url":"http:\/\/a33.wepolicy.cn\/api\/wlfs?v=158","data":{"where":{"shop":"3","expressstate":"4","wlcontent":"AP-\u5373\u5c06\u6d3e\u9001\u3001\u63d0\u9192\u7b7e\u6536\u6a21\u677f"},"var":{"id":"158","shop":"3","title":"AP-\u5373\u5c06\u6d3e\u9001\u3001\u63d0\u9192\u7b7e\u6536\u6a21\u677f","type":"2","message":"1","email":"3","ordertatus":"0","logisticstatus":"4","marketing":"0","carried":"0","repeattime":"0","sending":"0","timeinterval":"0","ktime":"1713888000","jtime":"1751212800","state":"1","statetime":"1713951981","emailtitle":"Your Alipearl hair\u00a0package will\u00a0be\u00a0delivered\u00a0ASAP","tab":"0","thq":"","thh":"","content":"Hey dear $firstName,Sorry for bothering you.<\/span><\/p>Your order has been shipped out by  $expressCompany , the tracking number is  $trackingNumber.<\/span><\/p>According to the tracking information, it has arrived in your country.Normally, the carrier company will arrange the final delivery for you in about 1 day. Please note that package delivery.<\/span><\/p>Note: It is better to schedule the delivery time and sign for the package so that you can get it safe and sound.<\/span><\/span><\/p>Have a good day. \u2765<\/span><\/p>","js":"","express":""}}}';
		$data = json_decode($data,true);
		$data = $data['data'];
		$webhookregister = 0;$cs = array();
		$where = $data['where'];
		$var = $data['var'];
		$wlfs = array();
		$shopid = $where['shop'];
		@$this->allocation->insert(array('title'=>date('Y-m-d',time()).'-'.$shopid));
		$where = "shop = '".$where['shop']."' and waybill != '' and library = '2' and expressstate <= '".$where['expressstate']."' and librarytime > '".(time()-22*24*3600)."' and wlcontent not like '%".$where['wlcontent']."%'";//正式发送的时候开启这个"'
		//$where = "shop = '".$where['shop']."' and waybill != '' and library = '2' and express = '3' and librarytime > '1636300800' and wlcontent not like '%".$where['wlcontent']."%'";//正式发送的时候开启这个"'
		$data = $this->fullorder->find_all("number  = 'ALIP-40410-155'");
		$csck = array();
			foreach ($data as $k=>$v)
		    {
				$vexpress = $v['express'];
				$shop = $this->shop->read($v['shop']);
				$express = $this->express->read($v['express']);
				$service = $this->service->read($express['service']); 
				$country = $this->country->read($v['country']);
				$v['country'] = $country['ename'];
				$express['servicename'] =$service['title'];//增加快递名称
				$v['cxcode'] = strtolower($express['cxcode']);//增加快递服务商码
				if($v['expressstate'] == $var['logisticstatus'] && $v['wlyc'] == '0' && $v['wltype'] != '1' && $v['source'] != '1')//获取快递状态等于模板状态、订单状态等于模板状态、出库时间大于-、未加入物流异常、允许发送邮件状态、非线下单
						{
							if($v['shop'] < '7')// && $v['shouldmoney'] > 100)
							{
								$wlfs[] = array('v'=>$v,'id'=>$var['id']);
								//$go = $this->_sdfs($v,$var['id']);//更新顺带发送
							}
							continue;
						}
		    	if(($express['cxcode'] == '' && $v['exstateerror'] == '') || ($express['cxcode'] == '' && $v['exstateerror'] != ''))
				{
					continue;
				}
				else if($express['cxcode'] == 'fedex' || $express['cxcode'] == 'usps' || $express['cxcode'] == 'dhl')// || $express['cxcode'] == 'cne' || $express['cxcode'] == 'dpex' || $express['cxcode'] == 'dpd'
				{
					/**
					if($express['cxcode'] == 'dpex' || $express['cxcode'] == 'dpd')
					{
						$express['cxcode'] = 'cne';
					}
					**/
					$logistics = $express['cxcode'];
				}
				else if(($express['cxcode'] == 'ups' || $express['cxcode'] == '17track') && $v['webhookregister'] == 1)
				{
					continue;
				}
				else if(($express['cxcode'] == 'ups' || $express['cxcode'] == '17track') && $v['webhookregister'] < 1)//使用webhook注册模式  || $express['cxcode'] == '17track'
				{
					$logistics = $express['cxcode'];
					$webhookregister = 1;
				}
				else
				{
					//暂时不启用第三方,这里直接跳出
					$this->fullorder->save(array('expressstate'=>'99'),$v['id']);
					continue;
					//$logistics = 'apismt';
					//$v['express'] = strtolower($express['cxcode']);//替换为快递服务商码
				}
		    	$v['servicename'] =$service['title'];//增加快递名称
		    	$v['url'] = $express['url'];//增加快递链接
		    	@$fs = $this->$logistics->get_logistics($v);
				$csck[] = array($v['number'],$fs['f']);
				if(!isset($fs['f']))
				{
					$fs = $this->$logistics->get_logistics($v);
					if(!isset($fs['f']))
				    {
						continue;
					}
					if($fs['f'] == '1')
					{
						$v['express'] = $vexpress;
						if($fs['exstate'] > $v['expressstate'] || isset($fs['webhookregister']))
						{
						    $this->fullorder->save(array('expressstate'=>$fs['exstate'],'excontent'=>$fs['data'],'webhookregister'=>$webhookregister),$v['id']);
						}
						if($fs['exstate'] == $var['logisticstatus'] && $v['wlyc'] == '0' && $v['wltype'] != '1' && $v['source'] != '1')//获取快递状态等于模板状态、订单状态等于模板状态、出库时间大于-、未加入物流异常、允许发送邮件状态、非线下单
						{
							if($v['shop'] < '7')// && $v['shouldmoney'] > 100)
							{
								$wlfs[] = array('v'=>$v,'id'=>$var['id']);
								//$go = $this->_sdfs($v,$var['id']);//更新顺带发送
							}
						}
					}
					/**
					if($logistics == 'apismt')//第三方未购买,第三方查询直接进入无法查询状态
					{
					    $this->fullorder->save(array('expressstate'=>'99'),$v['id']);
					}
					**/
				}
				else
				{
					if($fs['f'] == '1')
					{
						$v['express'] = $vexpress;
						if($fs['exstate'] > $v['expressstate'])
						{
						    $this->fullorder->save(array('expressstate'=>$fs['exstate'],'excontent'=>$fs['data'],'webhookregister'=>$webhookregister),$v['id']);
						}
						if($fs['exstate'] == $var['logisticstatus'] && $v['wlyc'] == '0' && $v['wltype'] != '1' && $v['source'] != '1')//获取快递状态等于模板状态、订单状态等于模板状态、出库时间大于-、未加入物流异常、允许发送邮件状态、非线下单
						{
							if($v['shop'] < '7')// && $v['shouldmoney'] > 100)
							{
								$wlfs[] = array('v'=>$v,'id'=>$var['id']);
								//$go = $this->_sdfs($v,$var['id']);//更新顺带发送
							}
						}
					}
				}
			}
			
		@$this->allocation->insert(array('title'=>$shopid.'-'.json_encode($csck)));
		if($wlfs)
		{
		    foreach ($wlfs as $k=>$v)
		    {
				$t1 = microtime(true);
                $this->_sdfs($v['v'],$v['id']);
                $t2 = microtime(true);
				$t3 = (40-($t2-$t1) < 1)?1:round(40-($t2-$t1));
			    sleep($t3);
				echo 1;
		    }
		}
	}
	
	
	
	public function _xx($arg_array)
	{
		$post = $this->input->post(NULL, TRUE);
		$api = $this->input->get('api',true);
		$dshop = $this->input->get('dshop',true);
		$gethl = array();
		/*  匹配加入  */
		$dictionaries = $this->typeclass->find_all('spare!= "" and classid != 1 and classid != 2 and classid != 3 and classid != 4 and classid != 5 and classid != 11 and classid != 16 and classid != 17 and classid != 20 and classid != 21 and classid != 23 and classid != 24 and classid != 29 and classid != 30 and classid != 31 and classid != 32 and classid != 36');
		// and (classid=13 or classid=22 or classid=8 or classid=15 or classid=27 or classid=25 or classid=26 or classid=18 or classid=14 or classid=9 or classid=12 or classid=10 or classid=6 or classid=100 or classid=999)
		$dtc = array();
		foreach ($dictionaries as $v) 
		{
			if(stripos($v['spare'],'|') !== false)//如果有多个值
			{
				$v['spare'] = explode('|',$v['spare']);
				foreach ($v['spare'] as $k=>$vs) 
		        {
					if(stripos($v['zh'],'|') !== false)
					{
						$vzh = explode('|',$v['zh']);
						$dtc[strtolower($vs)] = array('classid'=>$v['classid'],'zh'=>$vzh[$k],'id'=>$v['id'],'jm'=>$v['jm'],'spare'=>$vs);
					}
					else
					{
					    $dtc[strtolower($vs)] = array('classid'=>$v['classid'],'zh'=>$v['zh'],'id'=>$v['id'],'jm'=>$v['jm'],'spare'=>$vs);
					}
				}
			}
			else
			{
				$dtc[strtolower($v['spare'])] = array('classid'=>$v['classid'],'zh'=>$v['zh'],'id'=>$v['id'],'jm'=>$v['jm'],'spare'=>$v['spare']);
			}
			
		}
		$dictionaries2 = $this->typeclass->find_all();
		foreach ($dictionaries2 as $v)
		{
			$dtctitle[$v['id']] = $v['title'];
		}
		/*  匹配结束  */    
		/*  价格加入  */  
		$money = array();
		/**
		$productdescribe = $this->productdescribe->find_all('1=1','number,purchase,cost,salesprice,title');
		foreach ($productdescribe as $v) 
		{
			$money[$v['number']] = array('purchase'=>$v['purchase'],'cost'=>$v['cost'],'salesprice'=>$v['salesprice'],'title'=>$v['title']);
		}
		**/
		/*  价格加入  */
		/*  匹配ID加入  */
		$int = array();
		$intdata = $this->typeclass->find_all('classid=14','id,spare');
		foreach ($intdata as $v) 
		{
			$v['spare'] = explode('|',$v['spare']);
			$int[$v['id']] = $v['spare'][0];
		}
		/*  匹配ID结束  */
		/*  国家加入键值-k  */
		$cuy = array();
		$cuydata = $this->country->find_all('1=1','lb,id');
		foreach ($cuydata as $v) 
		{
			$cuy[$v['lb']] = $v['id'];//获取到国家ID
		}
		/*  国家加入键值-j  */
		$typeclass = array();
		$tdata = $this->typeclass->find_all('classid=30','id,title');
		foreach ($tdata as $v) 
		{
			$typeclass[$v['title']] = $v['id'];
		}
		$ex = array();
		$express = $this->express->find_all('1=1','id,title');
		foreach ($express as $v) 
		{
			$ex[$v['title']] = array('id'=>$v['id']);
		}
		/*  币种加入键值-j  */
		$zjsku = array();
		$shopsku = $this->shopsku->find_all();
		foreach ($shopsku as $val) 
		{
			$ss = explode(',',trim($val['shop'],','));
			foreach ($ss as $v) 
			{
				if(isset($zjsku[$v]))
				{
					$zjsku[$v] .= ','.trim($val['sku'],',');
				}
				else
				{
					$zjsku[$v] = trim($val['sku'],',');
				}
			}
		}	
		/*  支付方式-k  */
		$pay = array();$sd = array();
		$tdata = $this->typeclass->find_all('classid=4','id,spare');
		foreach ($tdata as $v) 
		{
			$paytype = $this->pay->get_typeclass($v['id']);
			if(isset($paytype['estimaterate']))
			{
				$estimaterate = $paytype['estimaterate'];
			}
			else
			{
				$estimaterate = 0;
			}
			if(stripos($v['spare'],'|') !== false)//如果有多个值
			{
				$v['spare'] = explode('|',$v['spare']);
				foreach ($v['spare'] as $k=>$vs) 
		        {
					$pay[$vs] = array('id'=>$v['id'],'estimaterate'=>$estimaterate);
				}
			}
			else
			{
				$pay[$v['spare']] = array('id'=>$v['id'],'estimaterate'=>$estimaterate);
			}
		}
		$time = time();
		$value = $this->shop->read($arg_array[0]);//TT店铺
			
				$setting = $this->setting->get_settings();
				$sjc = 15*3600+$setting['sctime'];//时间差
				$num = $this->fullordertt->find_count('gtime = "'.date('Ymd',$time).'" and shop = "'.$value['id'].'"');
				//$this->db->trans_begin();
				$res = $this->get_list($value,$time-5*24*3600,$time,'AWAITING_SHIPMENT',$cuy,$num,$dtc,$money,$int,$dtctitle,$pay,$typeclass,$ex,$sjc,$zjsku);//装运 AWAITING_SHIPMENT(111) ;-等待收集 AWAITING_COLLECTION (112);在途 IN_TRANSIT (121);-已交付 DELIVERED (122);- DELIVERED COMPLETED
				echo "
";
				print_r($res);
		}
		
		
		
		public function get_list($shop,$from,$to,$order_status,$cuy,$num,$dtc,$money,$int,$dtctitle,$pay,$typeclass,$ex,$sjc,$zjsku)//获取订单列表
	{
		$url = 'https://open-api.tiktokglobalshop.com';
		$link = '/order/202309/orders/search';
		$time = time();
		$post['create_time_ge'] = $from;
		$post['create_time_lt'] = $to;
		$post['order_status'] = $order_status;
		$queryParams['page_size'] = 100;
		$queryParams['sort_order'] = 'ASC';
		$queryParams['sort_field'] = 'create_time';
		$queryParams['shop_cipher'] =$shop['shop_cipher'];
		$queryParams['shop_id'] =$shop['codeid'];
		$queryParams['app_key'] =$shop['app_key'];
		$queryParams['shop_cipher'] =$shop['shop_cipher'];
		$queryParams['timestamp'] =$time;
		$link .= '?'.http_build_query($queryParams);
		$sign = $this->sign($link,$shop['app_secret'],$post);
		$url .= $link.'&sign='.$sign;
		$headers = array('Content-Type: application/json','x-tts-access-token:'.$shop['token']);
		$res = $this->su_curl($post,$url,$headers);
		$res = json_decode($res,true);
		$list = array();$page_token = '';$arr = array();
		if(isset($res['data']['orders']))
		{
			if($res['data']['total_count'] > 100)
			{
				$n = ceil($res['data']['total_count']/100);
				for($i=0;$i<$n;$i++)
				{
					$net_date = $this->get_next_list($shop,$from,$to,$order_status,$page_token);
					$page_token = $net_date[1];
					foreach ($net_date['0'] as $val) 
		        	{
						
							$list[] = $val['id'];
						
					}
				}
			}
			else
			{
			    foreach ($res['data']['orders'] as $val) 
		        {
				    
					    $list[] = $val['id'];
				    
			    }
			}
			$cs = array();
			if(count($list) > 50)
			{
				$n = ceil(count($list)/50);$x = 0;
				for($i=0;$i<$n;$i++)
				{
					$k = ($i<1)?0:$i*50;
					$data = array_slice($list,$k,50);
					$d = $this->get_data($data,$shop);
					$cs[] = $d;
					if(isset($d['data']))
		            {
					    foreach ($d['data']['orders'] as $val) 
		                {
						    $arr[$x] = $val;
							$x++;
					    }
					}
				}
			}
			else
			{
				$d = $this->get_data($list,$shop);
				if(isset($d['data']))
		        {
					 foreach ($d['data']['orders'] as $val) 
		             {
						 $arr[] = $val;
					 }
				}
			}
		}
		$read = array();
		$gnum = array();
		foreach ($arr as $val) 
		{
			$create_time = substr($val['create_time'],0,10)-$sjc;
			if(isset($gnum[date('ymd',$create_time)]))
			{
				$gnum[date('ymd',$create_time)] += 1;
			}
			else
			{
				$num = $this->fullordertt->find_count('gtime = "'.date('Ymd',$create_time).'" and shop = "'.$shop['id'].'"');
				$gnum[date('ymd',$create_time)] = $num+1;
			}
			$read[] = $val;
		}
		return array($read,$list);
	}
	
	public function get_next_list($shop,$from,$to,$order_status,$page_token='')//获取订单列表
	{
		$url = 'https://open-api.tiktokglobalshop.com';
		$link = '/order/202309/orders/search';
		$time = time();
		$post['create_time_ge'] = $from;
		$post['create_time_lt'] = $to;
		$post['order_status'] = $order_status;
		$queryParams['page_size'] = 100;
		$queryParams['sort_order'] = 'ASC';
		$queryParams['sort_field'] = 'create_time';
		$queryParams['shop_cipher'] =$shop['shop_cipher'];
		$queryParams['shop_id'] =$shop['codeid'];
		$queryParams['app_key'] =$shop['app_key'];
		$queryParams['shop_cipher'] =$shop['shop_cipher'];
		$queryParams['timestamp'] =$time;
		if($page_token)
		{
		    $queryParams['page_token'] = $page_token;
		}
		$link .= '?'.http_build_query($queryParams);
		$sign = $this->sign($link,$shop['app_secret'],$post);
		$url .= $link.'&sign='.$sign;
		$headers = array('Content-Type: application/json','x-tts-access-token:'.$shop['token']);
		$res = $this->su_curl($post,$url,$headers);
		$res = json_decode($res,true);
		if(isset($res['data']['orders']))
		{
			return array($res['data']['orders'],$res['data']['next_page_token']);
		}
	}
	
	public function get_data($list,$shop)
	{
		$url = 'https://open-api.tiktokglobalshop.com';
		$link = '/order/202309/orders';
		$time = time();
		$ids = implode(",",$list);
		$link .= '?shop_cipher='.$shop['shop_cipher'].'&app_key='.$shop['app_key'].'×tamp='.$time.'&ids='.$ids;
		$sign = $this->sign($link,$shop['app_secret'],'');
		$url .= $link.'&sign='.$sign;
		$headers = array('Content-Type: application/json','x-tts-access-token:'.$shop['token']);
		$res = $this->su_curl('',$url,$headers,$date_type='json',$timeout=300,$httptype="GET");
		$res = json_decode($res,true);
		return $res;
	}
	
	public function get_read($data,$time,$shop,$cuy,$num,$dtc,$money,$int,$dtctitle,$pay,$typeclass,$ex,$sjc,$zjsku)
	{
		$purl = 'https://shop.tiktok.com/view/product/';
		$link = '';$product = '';$sku = '';$quantity = '';
		$lpsq = array();
		foreach ($data['line_items'] as $v) 
		{
			if(isset($lpsq[$v['seller_sku']]))
			{
				$lpsq[$v['seller_sku']]['quantity'] += 1;
			}
			else
			{
				$lpsq[$v['seller_sku']] = array('link'=>$purl.$v['product_id'],'product'=>$v['product_name'],'sku'=>$v['seller_sku'],'quantity'=>1);
			}
		}
		foreach ($lpsq as $v) 
		{
			$link .= $v['link'].',';
			$product .= $v['product'].',';
			$sku .= $v['sku'].',';
			$quantity .= $v['quantity'].';';
		}
		if($data['status'] == 'DELIVERED' || $data['status'] == 'IN_TRANSIT' || $data['status'] == 'COMPLETED')
		{
			$s = 216;
		}
		else if($data['status'] == 'AWAITING_SHIPMENT')
		{
			$s = 207;
		}
		else if($data['status'] == 'CANCELLED')
		{
			$s = 217;
		}
		else
		{
			$s = 283;
		}
		if(isset($zjsku[$shop['id']]))//判断是否找到店铺SKU
		{
			$sku = rtrim($sku,',').','.$zjsku[$shop['id']];
		}
		$post['user_id'] = $data['user_id'];
		$post['state'] = $s;
		$post['shop'] = $shop['id'];//店铺ID
		$post['user'] = $shop['shopuser'];//店铺负责人
		$post['product'] = rtrim($product,',');//产品名称
		$post['link'] = rtrim($link,',');//产品链接
		$post['issku'] = rtrim($sku,',');
		$post['quantity'] = rtrim($quantity,';');
		$post['clientremarks'] = $data['buyer_message'];//客户备注
		$post['paypal'] = '';//交易号
		$post['guarantee'] = '';//卖家保障
		$post['parameter'] = '';//属性
		$post['shippingmethod'] = $data['delivery_option_name'].' '.$data['payment']['shipping_fee'];//用户选择快递方式及运费金额
		$post['source'] = 2;//订单类型
		$post['type'] = 1;//发货仓库
		$post['capital'] = 3;//资金支付状况,全部付款
		$post['number'] = $shop['shortname'].'-'.substr(date('ymd',substr($data['create_time'],0,10)-$sjc),1).'-'.(substr(strval($num+1000),1,3));//编号
		$post['orderinfo'] = $data['id'];//订单号
		$post['insurance'] = 0;//运输保险费用
		$address = $data['recipient_address']['address_detail'];
		$post['baddress'] = $address.','.$data['recipient_address']['district_info'][3]['address_name'].','.$data['recipient_address']['district_info'][1]['address_name'].','.$data['recipient_address']['postal_code'].','.$data['recipient_address']['region_code'].','.$data['recipient_address']['phone_number'];
		$post['saddress'] = $address.','.$data['recipient_address']['district_info'][3]['address_name'].','.$data['recipient_address']['district_info'][1]['address_name'].','.$data['recipient_address']['postal_code'].','.$data['recipient_address']['region_code'].','.$data['recipient_address']['phone_number'];
		$post['country'] = $cuy[$data['recipient_address']['region_code']];//此国家的ID
		$post['al'] = $data['recipient_address']['region_code'];//联邦名称
		$post['bname'] = preg_replace('/( | | |\s)/',' ',$data['recipient_address']['name']);//名称
		$post['sname'] = preg_replace('/( | | |\s)/',' ',$data['recipient_address']['name']);//名称
		$post['client'] = preg_replace('/( | | |\s)/',' ',$data['recipient_address']['name']);//公司名称
		$post['name'] = preg_replace('/( | | |\s)/',' ',$data['recipient_address']['name']);//收件人名称
		$post['phone'] = preg_replace('/\D/s','',$data['recipient_address']['phone_number']);//收件人电话
		$post['email'] = preg_replace('/( | | |\s)+/','',$data['buyer_email']);//客户邮箱
		$post['zipcode'] = $data['recipient_address']['postal_code'];//收件人邮编
		$post['province'] = $data['recipient_address']['district_info'][1]['address_name'];//收件人省份
		$post['city'] = $data['recipient_address']['district_info'][3]['address_name'];//收件人城市
		$post['address'] = $address;//收件人地址
		$post['shouldmoney'] = $data['payment']['total_amount'];//应收金额
		$post['skje'] = $post['shouldmoney'];//收款金额
		$post['ismoney'] = $data['payment']['currency'].$post['shouldmoney'];//支付币种金额
		$yga = $post['shouldmoney'];//金额
		$post['cf'] = ($data['shipping_type']=='SELLER')?0:1;//是否仓发TIKTOK平台仓发 SELLER商家发,ERP中1平台仓发,0商家发
		$post['budget'] = 0;
		if(isset($data['pay']) && $yga > 0)
		{
			$post['pay'] = $pay[$data['pay']]['id'];
			$ygc = $pay[$data['pay']]['estimaterate'];//预估到账公式
			$post['estimaterate'] = $pay[$data['pay']]['estimaterate'];
			$ifbudget = eval("return $yga*1.$ygc;");
			if($ifbudget > 0)
			{
			    $post['budget'] = eval("return $yga*1.$ygc;");//预估到帐金额
			}
		}
		else if($yga > 0)
		{
			$post['pay'] = 0;
			$ygb = $shop['estimaterate'];//店铺默认到账公式
			$post['estimaterate'] = $shop['estimaterate'];
			$ifbudget = eval("return $yga*1.$ygb;");
			if($ifbudget > 0)
			{
			    $post['budget'] = eval("return $yga*1.$ygb;");//预估到帐金额
			}
		}
		$post['overtime'] = $data['shipping_due_time']-$sjc;//超时时间
		$post['buytime'] = substr($data['paid_time'],0,10)-$sjc;//格式化付款时间
		$post['dtime'] = substr($data['create_time'],0,10)-$sjc;//订单时间
		$post['gtime'] = date('Ymd',substr($data['create_time'],0,10)-$sjc);//格式化订单时间
		$post['currencytitle'] = $data['payment']['currency'];//结算币种名称
		$post['currency'] = $typeclass[$data['payment']['currency']];//钱币ID
		$post['time'] = time();//同步时间
		$post['hl'] = '6.4';//汇率
		if(isset($data['delivery_option_name']))
		{
			$post['express'] = (isset($ex[$data['delivery_option_name']]))?$ex[$data['delivery_option_name']]['id']:0;//快递方式
		}
		if(isset($data['line_items'][0]['tracking_number']))
		{
			$post['waybill'] = $data['line_items'][0]['tracking_number'];
		}
		$matching = $this->api->matching($post['quantity'],$post['issku'],$dtc,$money,$int,$dtctitle);
		$post['shipremarks'] = $matching['title'];
		$post['cost'] = $matching['cost'];
		$post['purchase'] = $matching['purchase'];
		$post['fpdata'] = $matching['product'];
		$post['whlabel'] = $matching['whlabel'];
		$post['slpx'] = $matching['wcslpx'];
		return $post;
	}
	
	public function sign($url,$appSecret,$body='') 
	{
		// 解析URL获取查询参数
		$queryParams = array();
		parse_str(parse_url($url, PHP_URL_QUERY), $queryParams);
		// 排除'sign'和'access_token'
		unset($queryParams['sign'], $queryParams['access_token']);
		// 按字典顺序排序查询参数
		ksort($queryParams);
		// 拼接参数为{key}{value}格式
		$input = '';
		foreach ($queryParams as $key => $value)
		{
    		$input .= $key . $value;
		}
		// 追加请求路径
		$path = parse_url($url, PHP_URL_PATH);
		$input = $path . $input;
		if ($body) 
		{
			$input .= json_encode($body);
	    }
		// 使用app_secret包裹生成的字符串
		$input = $appSecret . $input . $appSecret;
		// 生成签名
		$sign = hash_hmac('sha256', $input,$appSecret);
        return $sign;
	}
	


	
	public function _aasd($arg_array)//DHL
	{
		$token_header = array(
            'x-request-id: 605062090',
			'Content-Type: application/json'
        );
		$ch = curl_init();
		$url = 'https://webhub.cndhl.com/dps/dps-auth-server/api/gateway-token/generate';
		curl_setopt($ch,CURLOPT_URL,$url);
		curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
		curl_setopt($ch, CURLOPT_HTTPHEADER, $token_header);
		//curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //TRUE 将curl_exec()获取的信息以字符串返回,而不是直接输出。
		//curl_setopt($ch, CURLOPT_HEADER, true); //返回response头部信息
		curl_setopt($ch,CURLOPT_POST, 1);
		curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,600);
        //设置post数据
		$post = array();
		$post['consumerCode'] = 'P_f7yzl4675s';
		$post['key'] = 'wt)!ftX{1Co$/i{|';
		$data = json_encode($post);
        curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
		$res = curl_exec($ch);
		curl_close($ch);
echo $res;
		exit;
		
		$y = $this->fullorder->get_number($arg_array[0]);
		$fpdata = $y['fpdata'];
		$weight = 0;
		$fpdataweight = str_replace(array('-163-','-164-','-165-','-166-'),'-',$fpdata);
        $list = $fpdataweight;
		$list = explode(';',trim($list,';'));
		$cs = array();
		foreach ($list as $vv)
		{
			$asd = explode('|',trim($vv,'|'));
			$c = explode(',',trim($asd[0],','));
			if(!isset($c[1]))
			{
				continue;
			}
			else
			{
				$dweight = $this->weight->get_cc($c);
				$cs[] = array($vv,$dweight);
				$weight += $dweight*$asd[2];
			}
		}
		echo "
";
		print_r($cs);
		exit;
		
		$w = $this->dhl->get_logistics($y);
		
		echo "
";
		print_r($w);
		echo "
";
		print_r($y);
		
		
		exit;
		$y = $this->fullorder->get_number("KISS-40318-068");
		$express = $this->express->read($y['express']);
	if($express['printcode'] == "DHLUSA" && $y['waybill'] != '')
			{
				$d = $this->dhl->get_data_9610($y);
				if($d != 1)
				{
					$this->allocation->insert(array('order'=>1,'title'=>$y['number'],'content'=>$d));
					return '9610失败,'.$d;exit;
				}
				$this->allocation->insert(array('order'=>9610,'title'=>$y['number']));
			}
			
			exit;
		
		$d = $this->dhl->get_data_9610($data);
			echo "
";
		print_r($d);
		exit;
		
		
		
		$list = $this->whlabel->find_pc("type != 0",'sku,features,warehouse','id,warehouse,sku,type,features');
		foreach ($list as $v) 
		{
		   $a += $this->whlabel->find_count("sku =  '".$v['sku']."' and features =  '".$v['features']."' and warehouse = '".$v['warehouse']."' and type = '0'");		
		
		}
		echo $a;
				exit;
		$t = $this->shop->token(2);

           $data = '?';
		   //$data .= 'searchCriteria[filterGroups][0][filters][0][field]=Field';//字段名称
		   //$data .= '&searchCriteria[filterGroups][0][filters][0][value]=Value';//字段内容
		   //$data .= '&searchCriteria[filterGroups][0][filters][0][conditionType]=ConditionType';//字段类型
		   //$data .= '&';
		   $data .= 'searchCriteria[sortOrders][0][field]=created_at';
		   $data .= '&searchCriteria[sortOrders][0][direction]=DESC';
		   $data .= '&searchCriteria[pageSize]=10';
		   $data .= '&searchCriteria[currentPage]=1';
		   //$url = 'http://pc.hnwmzp.cn/rest/all/V1/orders/items'.$data;
		   $url = 'http://pc.hnwmzp.cn/rest/V1/orders/109933';
		   $a = $this->api->su_curl('',$url,$header=array("Authorization: Bearer ".$t,"Content-Type: application/json"),$date_type='json',$timeout=300,$httptype="GET",$userpwd='');
		   $a = json_decode($a,true);
			echo "
";
		print_r($a);
		exit;

		
		
		/**
		$ch = curl_init();
        $post = array();
		$ai['username'] = 'longyiapi';
		$ai['password'] = 'longyi123';
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, 'http://pc.hnwmzp.cn/rest/V1/integration/admin/token');
		curl_setopt($ch, CURLOPT_POST, 1);
		curl_setopt($ch, CURLOPT_HEADER, 0);
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
		curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
		curl_setopt($ch, CURLOPT_POSTFIELDS,$ai);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,900);
		$res = curl_exec($ch);
		curl_close($ch);
		$res  = json_decode($res ,true);
		echo "
";
		print_r($res);
		
		//echo $c['data']['order_list']['0']['order_line_list']['0']['tracking_number'];
		/**
		$y = $this->fullordertt->find_all("dtime < 1708012800 and (whlabel like '%x|%' or whlabel like '%u|%')",'number');
		foreach ($y as $v) 
		{
			$a = $this->whlabel->find_all("z");
		}
		
		$asd = '';
		$a = $this->whlabel->find_all("zd like '%TT-%' and state = 0",'id,zd');
		foreach ($a as $v) 
		{
			$c = explode('-',$v['zd']);
			if($c[2] < 40215)
			{
				//$this->whlabel->save(array('zd'=>''),$v['id']);
			}
		}
		echo "
";
		print_r($asd);
		**/
	}
	
	public function su_curl($data,$url,$header=array(),$date_type='json',$timeout=300,$httptype="POST",$userpwd='')
    {
    
        if ($date_type == 'http_build_query')
		{
            $data = http_build_query($data);
        }
		else if ($date_type == 'json')
		{
            $data = json_encode($data);
        }
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HEADER, false);
        switch ($httptype)
		{
            case "GET":
            curl_setopt($ch, CURLOPT_HTTPGET, true);
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
            break;
			
            case "POST":
            curl_setopt($ch, CURLOPT_POST, true);
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
            break;
			
            case "PUT":
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
            break;
			
            case "DELETE":
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
            break;
        }
        $isSecure = strpos($url, "https://");
        if ($isSecure === 0)
		{
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        }
        if(!empty($header))
		{
            curl_setopt($ch, CURLOPT_SSLVERSION , 6); //NEW ADDITION
            curl_setopt($ch,CURLOPT_HTTPHEADER,$header);
        }

        if(!empty($userpwd))
		{
            curl_setopt($ch,CURLOPT_USERPWD,$userpwd);
        }
        curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
        $result = curl_exec($ch);
        curl_close($ch);
        return $result;
	}

}