php获取微信 openid

header ( ‘content-type:text/html’ );header ( ‘content-type:text/html’ ); header ( ‘charset:utf-8’ ); $wxcode = $_GET[‘code’]; $wxstate = $_GET[‘state’]; define ( “APPID”, “aaaaaaaaaaaaaaaaaaaaaaaaa” ); define ( “APPSECRET”, “xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx” ); if ($wxcode!=”){ $token_access_url = “https://api.weixin.qq.com/sns/oauth2/access_token?appid=” . APPID . “&secret=” . APPSECRET . “&code=” . $wxcode . “&grant_type=authorization_code”; echo “token_access_url:”.$token_access_url.”<br />”; $res = file_get_contents($token_access_url); // 获取文件内容或获取网络请求的内容 //echo “res:”.$res.”<br />”; $result = json_decode($res,true); // 接受一个 JSON 格式的字符串并且把它转换为 PHP 变量 $access_token = $result[‘access_token’]; //echo “access:”.$access_token; $expires_in = $result[‘expires_in’]; $weixin_id = (string)$result[‘openid’]; $scope = $result[‘scope’]; $unionid = $result[‘unionid’]; //echo “weixin_id:”.$weixin_id.”<br />”;

php 连接SQLSERVER2008 并读取16进制图片编码转存本地文件

$fgid = $_GET[‘fgid’];
$connectionInfo = array(“UID”=>”sa”,”PWD”=>”xxx”,”Database”=>”lj”);
$con = sqlsrv_connect(‘127.0.0.1’,$connectionInfo) or die (“err01”);
$query = “SELECT top 10 buiImg from TB_UserInfoImg where buiCode = ‘$fgid'”;
$val=sqlsrv_query($con,$query);
while($row=sqlsrv_fetch_array($val)){
// echo $row[0];
//echo base64_encode($row[0]);
//echo ‘<img src=”data:image/jpg;base64,’.base64_encode($row[0]).'” />’;
$imgdata = ‘data:image/bmp;base64,’.base64_encode($row[0]);
//echo $imgdata.'<br>’;
//匹配出图片的格式

//匹配出图片的格式
if (preg_match(‘/^(data:\s*image\/(\w+);base64,)/’, $imgdata, $result)){
$type = $result[2];
$new_file = “uploads/userup/”;
if(!file_exists($new_file))
{
//检查是否有该文件夹,如果没有就创建,并给予最高权限
mkdir($new_file, 0700);
}
$new_file = $new_file.$fgid.”.{$type}”;
if (file_put_contents($new_file, base64_decode(str_replace($result[1], ”,$imgdata)))){
echo ‘/’. $new_file;
}else{
echo ‘/uploads/userup/100001.bmp’;
}
}
}

给个演示输出的PHP:index