eaglephp运用微信api接口开发微信框架_php指南
发表时间:2018-12-06 来源:学卫网整理相关软件相关文章人气:
(isset($jsonArr['errcode']) && $jsonArr['errcode'] > 0)) $this->error($jsonArr);
else return $jsonArr;
}
return false;
}
/**
* 通过ticket换取二维码
* 获取二维码ticket后,开发者可用ticket换取二维码图片。请注意,本接口无须登录态即可调用。
* 提醒:TICKET记得进行UrlEncode
* ticket正确情况下,http 返回码是200,是一张图片,可以直接展示或者下载。
* 错误情况下(如ticket非法)返回HTTP错误码404。
*
* @param string $ticket
*/
public function getQrcodeUrl($ticket)
{
return self::SHOW_QRCODE_URL.'ticket='.urlencode($ticket);
}
/**
* 记录接口产生的错误日志
*/
public function error($data)
{
$this->errCode = $data['errcode'];
$this->errMsg = $data['errmsg'];
Log::info('WEIXIN API errcode:['.$this->errCode.'] errmsg:['.$this->errMsg.']');
}
/**
* 将数组中的中文转换成json数据
* @param array $arr
*/
public function jsonEncode($arr) {
$parts = array ();
$is_list = false;
//Find out if the given array is a numerical array
$keys = array_keys ( $arr );
$max_length = count ( $arr ) - 1;
if (($keys [0] === 0) && ($keys [$max_length] === $max_length )) { //See if the first key is 0 and last key is length - 1
$is_list = true;
for($i = 0; $i < count ( $keys ); $i ++) { //See if each key correspondes to its position
if ($i != $keys [$i]) { //A key fails at position check.
$is_list = false; //It is an associative array.
break;
}
}
}
foreach ( $arr as $key => $value ) {
if (is_array ( $value )) { //Custom handling for arrays
if ($is_list)
$parts [] = $this->jsonEncode ( $value ); /* :RECURSION: */
else
$parts [] = '"' . $key . '":' . $this->jsonEncode ( $value ); /* :RECURSION: */
} else {
$str = '';
if (! $is_list)
$str = '"' . $key . '":';
//Custom handling for multiple data types
if (is_numeric ( $value ) && $value<2000000000)
$str .= $value; //Numbers
elseif ($value === false)
$str .= 'false'; //The booleans
elseif ($value === true)
$str .= 'true';
else
$str .= '"' . addslashes ( $value ) . '"'; //All other things
// :TODO: Is there any more datatype we should be in the lookout for? (Object?)
$parts [] = $str;
}
}
$json = implode ( ',', $parts );
if ($is_list)
return '[' . $json . ']'; //Return numerical JSON
return '{' . $json . '}'; //Return associative JSON
}
/**
* 检验签名
*/
public function checkSignature()
{
$signature = HttpRequest::getGet('signature');
$timestamp = HttpRequest::getGet('timestamp');
$nonce = HttpRequest::getGet('nonce');
$token = $this->token;
$tmpArr = array($token, $timestamp, $nonce);
sort($tmpArr);
$tmpStr = implode($tmpArr);
$tmpStr = sha1($tmpStr);
return ($tmpStr == $signature ? true : false);
}
/**
* 验证token是否有效
*/
public function valid()
{
if($this->checkSignature()) exit(HttpRequest::getGet('echostr'));
}
}
微信支持多种语言,支持Wi-Fi无线局域网、2G,3G和4G移动数据网络,iOS版,Android版、Windows Phone版、Blackberry版、诺基亚S40版、S60V3和S60V5版
。