<?php
header('Content-type: text/html; charset=utf-8');#设置头信息
require_once('zhphpWeixinApi.class.php');#加载微信接口类文件
$zhwx=new zhphpWeixinApi();//实例化
$configArr=array(
'token'=>'weixintest',
'appid'=>'wx7b4b6ad5c7bfaae1',
'appSecret'=>'faaa6a1e840fa40527934a293fabfbd1',
'myweixinId'=>'gh_746ed5c6a58b'
);
$zhwx->setConfig($configArr);//配置文件
$zhwx->weixinBaseApiMessage();
$zhwx->checkAccessToken();
$userlist=$zhwx->getUserList();//得到用户列表
/**
*发送图文:
* 第一步: 将服务器的图片上传到微信平台 返回media_id 通常将该值保存 $callData=$zhwx->mediaUpload('image','cc.jpg');
保存media_id:
ZX8vrTIY9L7TVG74QHNb2-CDOObUKd37aHryTzsXScp0gMFUiaDaVkbgdPIbfP4a
qpANYf9_fNYW3CvCnh_B0V98-el7DCsLT7SuHGGc4VTM2U0U6EjOypp78Y1ruURN
2fA6TuZOQjanrkZj5x8vX2evA3cLJnmbaNMjl5ZBih0l0K0d9Bw1cqZdJUS4coVc
* 第二步: 准备数据,上传图文信息
*
$data=array(
array(
"thumb_media_id"=>"ZX8vrTIY9L7TVG74QHNb2-CDOObUKd37aHryTzsXScp0gMFUiaDaVkbgdPIbfP4a",
"author"=>"zhphp",
"title"=>"绿色资源-给天空草地一片绿色",
"content_source_url"=>"http://wxphptest1.applinzi.com/aa.php",
"content"=>"<div style='width: 100%; height: 50px; background-color: red;'>文章内容</div>",
"diges"=>"digest"
),
array(
"thumb_media_id"=>"qpANYf9_fNYW3CvCnh_B0V98-el7DCsLT7SuHGGc4VTM2U0U6EjOypp78Y1ruURN",
"author"=>"zhphp",
"title"=>"微信图书推荐",
"content_source_url"=>"http://wxphptest1.applinzi.com/bb.php",
"content"=>"<div style='width: 100%; height: 50px; background-color: red;'>文章内容</div>",
"diges"=>"digest"
),
array(
"thumb_media_id"=>"2fA6TuZOQjanrkZj5x8vX2evA3cLJnmbaNMjl5ZBih0l0K0d9Bw1cqZdJUS4coVc",
"author"=>"zhphp",
"title"=>"一对人儿",
"content_source_url"=>"http://wxphptest1.applinzi.com/bb.php",
"content"=>"<div style='width: 100%; height: 50px; background-color: red;'>文章内容</div>",
"diges"=>"digest"
),
);
$callData=$zhwx->newsUpload($data);
$newMediaId=$callData['media_id'];//这个 media_id 是群发资源的id
//再次返回 media_id = 8wmuW_y3SrzCn5I7p-vvZliVvyhAqtYer4zjn-Sr4CRZ6rxxFgQT9hL8NzD4J3F0
* 第三步: 主动发送图文消息
*/
if(isset($_POST['sub'])){
$touser=$_POST['userOpenId'];
$data=$zhwx->sendMassMessage('news',$touser,'8wmuW_y3SrzCn5I7p-vvZliVvyhAqtYer4zjn-Sr4CRZ6rxxFgQT9hL8NzD4J3F0'); ##主动发送图文消息
if($data['errcode'] == 0){
echo '主动发送图文信息成功';
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>微信群发信息</title>
<style type="text/css">
.userlistBox{
width: 1000px;
height: 300px;
border: 1px solid red;
}
td{ text-align: center; border: 1px solid black;}
</style>
</head>
<body>
<?php
$userinfos=array();
foreach($userlist['data'] as $key=>$user){
foreach($user as $kk=>$list){
$userinfos[]=$zhwx->getUserInfo($list);
}
}
?>
<form action="wx.php?act=send" method="post">
<div class="userlistBox">
<h2>请选择用户</h2>
<table >
<tr>
<th style="width: 10%;">编号</th>
<th style="width: 15%;">关注事件类型</th>
<th style="width: 15%;">用户姓名</th>
<th style="width: 10%;">性别</th>
<th style="width: 15%;">头像</th>
<th style="width: 15%;">所在地</th>
<th style="width: 15%;">所在组</th>
<th style="width: 5%;">操作</th>
</tr>
<?php
foreach($userinfos as $key=>$userinfo){
?>
<tr>
<td><?php echo $key+1;?></td>
<td><?php
if($userinfo['subscribe'] == 1){
echo '普通关注事件';
}
?></td>
<td> <?php echo $userinfo['nickname']; ?></td>
<td> <?php echo $userinfo['sex']==1?'男':'女'; ?></td>
<td> <?php
if(empty($userinfo['headimgurl'])){
echo '没有头像';
}else{
echo '<img width="50px" height="50px" src="'.$userinfo['headimgurl'].'">';
}
?></td>
<td><?php echo $userinfo['country'].'-'.$userinfo['province'].'-'.$userinfo['city']; ?></td>
<td><?php
if($userinfo['groupid'] == 0){
echo '没有分组';
}else{
echo '还有完善功能';
}
?>
</td>
<td><input type="checkbox" value="<?php echo $userinfo['openid'];?>" name="userOpenId[]" id="m_<?php echo $key+1; ?>" /></td>
</tr>
<?php
}
?>
</table>
<input type="submit" name="sub" value="发送" />
</div>
</form>
</body>
</html>
微信粉丝主动推送信息或者商品
猜你喜欢
转载自blog.csdn.net/echocdzh/article/details/50699787
今日推荐
周排行