qq 登录api php类(5)
来源:未知 责任编辑:责任编辑 发表时间:2015-09-16 20:04 点击:次
//构造签名串.源串:方法[GET|POST]&uri&参数按照字母升序排列
$sigstr = “POST”.”&”.”$url”.”&”;
//必要参数,不要随便更改!!
$params = $_POST;
$params["oauth_version"] = “1.0″;
$params["oauth_signature_method"] = “HMAC-SHA1″;
$params["oauth_timestamp"] = time();
$params["oauth_nonce"] = mt_rand();
$params["oauth_consumer_key"] = $appid;
$params["oauth_token"] = $access_token;
$params["openid"] = $openid;
unset($params["oauth_signature"]);
//获取上传图片信息
foreach ($_FILES as $filename => $filevalue)
{
if ($filevalue["error"] != UPLOAD_ERR_OK)
{
//echo “upload file error $filevalue['error']\n”;
//exit;
}
$params[$filename] = file_get_contents($filevalue["tmp_name"]);
}
//对参数按照字母升序做序列化
$sigstr .= $this->get_normalized_string($params);
//签名,需要确保php版本支持hash_hmac函数
$key = $appkey.”&”.$access_token_secret;
$signature = $this->get_signature($sigstr, $key);
$params["oauth_signature"] = $signature;
//处理上传图片
foreach ($_FILES as $filename => $filevalue)
{
$tmpfile = dirname($filevalue["tmp_name"]).”/”.$filevalue["name"];
move_uploaded_file($filevalue["tmp_name"], $tmpfile);
$params[$filename] = “@$tmpfile”;
}
/*
echo “len: “.strlen($sigstr).”\n”;
echo “sig: $sigstr\n”;
echo “key: $appkey&\n”;
*/
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_URL, $url);
$ret = curl_exec($ch);
//$httpinfo = curl_getinfo($ch);
//print_r($httpinfo);
curl_close($ch);
//删除上传临时文件
unlink($tmpfile);
return $ret;
}
/**
* @brief 所有post 请求都可以使用这个方法
*
* @param $url
* @param $appid
* @param $appkey
* @param $access_token
* @param $access_token_secret
* @param $openid
*
*/
function do_post($url, $appid, $appkey, $access_token, $access_token_secret, $openid)
{
//构造签名串.源串:方法[GET|POST]&uri&参数按照字母升序排列
$sigstr = “POST”.”&”.rawurlencode($url).”&”;
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>