send_wx_a($order['user_id'],$sn);
/**
* 发消息
*/
function send_wx_a($user_id,$sn) {
//发送微信消息
// wechat($sn);
//粉丝购物有提醒Start
$m_info = M('users')->where('user_id = ' . $user_id)->field('parent_id,openid,nick_name')->find();
$p_info = M('users')->where('user_id = ' . $m_info['parent_id'])->find();
if ($p_info['openid']) {
$send_array[]=array('openid'=>$p_info['openid'],'content'=>'您的粉丝【'.$m_info['nick_name'].'】在 时间:' . date('Y-m-d H:i:s',time()) . '成功购买了商城的商品');
$sends_array[]=array('openid'=>$m_info['openid'],'content'=>'您在时间:' . date('Y-m-d H:i:s',time()) . '成功购买了商城的商品');
}
if(!empty($send_array)) {
send_wx_message($send_array);
send_wx_message($sends_array);
}
//粉丝购物有提醒End
}
/**
* 发送客服消息
* @param array $send_array 二维数组,包括openid,发送内容
* @return [type] [description]
*/
function send_wx_message($send_array=array(array('openid'=>'o_ev71H7Dd7bdLlZgEt84X0uSiGU','content'=>'发送内容')))
{
$access_token = wx_access_token();
if ($access_token) {
foreach ($send_array as $key => $value) {
$send_url = 'https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token='.$access_token;
$send_res = '{"touser":"'.$value['openid'].'","msgtype":"text","text":{"content":"'.$value['content'].'"}}';
// $result = http_request($send_url,$send_res);
$result = http_request_wx($send_url,$send_res);
}
// $result = json_decode($result);
// $result = objectToArray($result);
// dump($result);
}
}
function http_request_wx($url, $data = array()) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
// 我们在POST数据哦!
curl_setopt($ch, CURLOPT_POST, 1);
// 把post的变量加上
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}