前一段时间项目中遇到一个稍微麻烦一点的问题。
后来在写代码的过程中却发现,并不行。 //先添加客服 function addkf() { $token = getToken(); $url = 'https://api.weixin.qq测试数据/customservice/kfaccount/add?access_token='.$token; $data = '{ "kf_account" : "system@system", "nickname" : "客服1", "password" : "admin", }'; echo https_request($url,$data); } //获取access_token的方法。 function getToken() { $appid = 'appid'; $appsecret = 'appsecret'; $token_file = dirname(dirname(detest_file)).'/data/token.txt'; if(!file_exists($token_file) || ((time() - filemtime($token_file)) > 7000)){ $TOKEN_URL="https://api.weixin.qq测试数据/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$appsecret; $json=file_get_contents($TOKEN_URL); $result=json_decode($json); $ACC_TOKEN=$result->access_token; file_put_contents($token_file,$ACC_TOKEN); }else{ $ACC_TOKEN = file_get_contents($token_file); } return $ACC_TOKEN; } //调用发送方法 function sendmsg($content,$openid) { $token = getToken(); $url = 'https://api.weixin.qq测试数据/cgi-bin/message/custom/send?access_token='.$token; $content = '感谢你的关注\n回复你厉害 \n例如 回复123456 '; $data = '{ "touser":"'.$openid.'", "msgtype":"text", "text": { "content":"'.$content.'" } }'; https_request($url,$data); return true; } /** * request 请求 */ function https_request($url, $data = null){ $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE); if (!empty($data)){ curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $data); } curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($curl); curl_close($curl); return $output; } 总结
以上所述是小编给大家介绍的微信公众号之主动给用户发送消息功能,希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,小编会及时回复大家的!
查看更多关于微信公众号之主动给用户发送消息功能的详细内容...