【实例简介】
通过php对微信公众号开发,实现在组织、部门等成员较多的情况下查询通讯录的功能,从而获取待查询人的手机号、所在部门、部门职位等信息。
【实例截图】
【核心代码】
function getInfo($name)
{
$phonenumber = getNumber($name);
if ($phonenumber == "")
{
$output = "经查询,数据库中无此人信息!";
}
else
{
$output = "经查询,".$name."的手机号码为:".$phonenumber;
}
return $output;
}
function getNumber($name)
{
$mysql_host = SAE_MYSQL_HOST_M;
$mysql_host_s = SAE_MYSQL_HOST_S;
$mysql_port = SAE_MYSQL_PORT;
$mysql_user = SAE_MYSQL_USER;
$mysql_password = SAE_MYSQL_PASS;
$mysql_database = SAE_MYSQL_DB;
$mysql_table = "roster";
$mysql_state = "SELECT * FROM ".$mysql_table." WHERE 'roster_name' = '".$name."'";
$con = mysql_connect($mysql_host.':'.$mysql_port, $mysql_user, $mysql_password, true);
if (!$con){
die('Could not connect: ' . mysql_error());
}
mysql_query("SET NAMES 'UTF8'");
mysql_select_db($mysql_database, $con);
$result = mysql_query($mysql_state);
$phonenumber = "";
while($row = mysql_fetch_array($result))
{
$phonenumber = $row['roster_phonenumber'];
break;
}
mysql_close($con);
return $phonenumber;
}