アップロード写真マイクロチャネルの顧客サービスのニュース

パブリック関数uploadWXImg($ imgpath、$ ID){ 
	$ mp_infoModel = M( 'ゲーム')。
	$ mp_info = $ mp_infoModel->検索($ ID); 
	$ TOKEN =の$ this - > get_access_token($ mp_info [ 'APP_ID']、$ mp_info [ 'app_secret'])。
	$ URL =。 'のhttps:?//api.weixin.qq.com/cgi-bin/media/upload access_tokenは=' $ TOKEN '&タイプ=画像'; 
	$データ= [ 'メディア' =>'@'.$ imgpath]。
	$結果=の$ this - > curl_post($ URL、$データ); 
	$データ= @json_decode($結果、真の); 
	[ 'media_idこの'] $のデータを返します。
} 
/ ** 
 *获取トークン
 * @param文字列$ APPID 
 * @param文字列$ appSecret 
 * @return混合
 * / 
get_access_tokenパブリック関数($のAppID = ''、$ appSecret = ''
	$ URL = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appId&secret=$appSecret"。
	$結果=のfile_get_contents($ URL); 
	$結果= json_decode($ trueの場合、結果); 
	$ accesstoken = $結果[ 'access_tokenは']; 
	$ accesstokenを返します。
} 

パブリック関数curl_post($ URL、$データ= NULL)
{ 
	$カール= curl_init(); 
	ますcurl_setopt($カール、CURLOPT_SAFE_UPLOAD、FALSE); 
	ますcurl_setopt($カール、CURLOPT_URL、$ URL); 
	ますcurl_setopt($カール、CURLOPT_SSL_VERIFYPEER、FALSE); 
	ますcurl_setopt($カール、CURLOPT_SSL_VERIFYHOST、FALSE); 
	もし{(空($データ)!)
	    しますcurl_setopt($カール、CURLOPT_POST、1); 
		$ hadFileは偽=。
		もし(IS_ARRAY($データ)&& ISSET($データ[ 'メディア'])){ 
			/ *支持文件上传* / 
			IF(でclass_exists( '\ CURLFile')){ 
				しますcurl_setopt($カール、CURLOPT_SAFE_UPLOAD、真の);  
		$ tmpdatastr =(!$ && hadFile IS_ARRAY($ postfields))?http_build_query($ postfields):$ postfields。
				foreachの{($キー=> $値として$データ)
					の場合(の$ this - > isPostHasFile($値)){ 
						$ postfields [$キー] =新しい\ CURLFile(のrealpath(LTRIM($値、 '@'))) ; 
						$ hadFileは真=。
					} 
				} 
			} ELSEIF(定義( 'CURLOPT_SAFE_UPLOAD')){ 
				IF(の$ this - > isPostHasFile($値)){ 
					ますcurl_setopt($カール、CURLOPT_SAFE_UPLOAD、偽)。
					$ hadFileは真=。
				} 
			} 
		} 
		ますcurl_setopt($カール、CURLOPT_POSTFIELDS、$ tmpdatastr)。
	} 
	ますcurl_setopt($カール、CURLOPT_RETURNTRANSFER、1)。
	$出力= curl_exec($カール)。
	curl_close($カール)。
	$出力を返します。
} 
パブリック関数isPostHasFile($値)
{ 
	場合(($値)&& strpos($値をIS_STRING '@')=== 0 && is_file(のrealpath(LTRIM($値を、 '@')))){ 
		trueを返します。
	} 
	falseを返します。
}

  

おすすめ

転載: www.cnblogs.com/setevn/p/11810361.html