您好,欢迎访问一九零五行业门户网

微信公众号开发之微信公共平台消息回复类

微信公众号开发代码我在网上看到了有不少,其实都是大同小义了都是参考官方给出的demo文件进行修改的,下面给各位分享一个。
初次接触的时候写的一些,有点乱…也没去整理…
ps—最近都不想工作了,各种烦,午饭也没吃,就是想表达一下我过的不好。—请忽略个人情绪往下看。
fromusername, $object->tousername, time() , $content, $flag); echo $resultstr; exit(); } /* *图片消息回复 *@param array object *@param string url *@return string */ public function resimage($object, $media_id) { $xmlimage = ; $xmlimage.= ; $xmlimage.= ; $xmlimage.= %s; $xmlimage.= ; $xmlimage.= ; $xmlimage.= ; $resultstr = sprintf($xmlimage, $object->fromusername, $object->tousername, time() , $media_id); echo $resultstr; exit(); } /* *图文消息回复 *@param array object *@param array newsdata 二维数组 必须包含[title][description][picurl][url]字段 *@return string */ public function resnews($object, $newsdata = array()) { $createtime = time(); $funcflag = 0; $newtplheader = fromusername}]]> tousername}]]> {$createtime} %s; $newtplitem = ; $newtplfoot = %s ; $content = ''; $itemscount = count($newsdata); $itemscount = $itemscount $item) { if ($key fromusername, $object->tousername, time() , $musiccontent[0]['title'], $musiccontent[0]['description'], $musiccontent[0]['musicurl'], $musiccontent[0]['hqmusicurl']); echo $resultstr; exit(); } /* *上传多媒体文件接口 *@param *@param array mediaarr filename、filelength、content-type *@return object */ public function uploadmedia($accesstoken, $type = 'image', $mediaarr) { $url = http://file.api.weixin.qq.com/cgi-bin/media/upload?access_token= . $accesstoken . &type= . $type; $dopost = self::curlpost($mediaarr, $url); return $dopost; } /* *gps,谷歌坐标转换成百度坐标 *@param lnt *@param lat *@return array */ public function mapapi($lng, $lat, $type) { $map = array(); if ($type == 'gps') { $url = http://map.yanue.net/gpsapi.php?lat= . $lat . &lng= . $lng; $res = json_decode(file_get_contents($url)); $map['lng'] = $res->baidu->lng; $map['lat'] = $res->baidu->lat; } if ($type == 'google') { $url = http://api.map.baidu.com/ag/coord/convert?from=2&to=4&mode=1&x= . $lng . &y= . $lat; $res = json_decode(file_get_contents($url)); $map['lng'] = base64_decode($res[0]->x); $map['lat'] = base64_decode($res[0]->y); } return $map; } /************************************************************** * * 使用特定function对数组中所有元素做处理 * @param string &$array 要处理的字符串 * @param string $function 要执行的函数 * @return boolean $apply_to_keys_also 是否也应用到key上 * @access public * *************************************************************/ public function arrayrecursive(&$array, $function, $apply_to_keys_also = false) { static $recursive_counter = 0; if (++$recursive_counter > 1000) { die('possible deep recursion attack'); } foreach ($array as $key => $value) { if (is_array($value)) { self::arrayrecursive($array[$key], $function, $apply_to_keys_also); } else { $array[$key] = $function($value); } if ($apply_to_keys_also && is_string($key)) { $new_key = $function($key); if ($new_key != $key) { $array[$new_key] = $array[$key]; unset($array[$key]); } } } $recursive_counter--; } /************************************************************** * * 将数组转换为json字符串(兼容中文) * @param array $array 要转换的数组 * @return string 转换得到的json字符串 * @access public * *************************************************************/ public function json($array) { self::arrayrecursive($array, 'urlencode', true); $json = json_encode($array); return urldecode($json); } /* *创建菜单 * */ public function creatmenu($shop_id, $data) { $jsonarray = self::json($data); $accesstoken = self::accesstoken($weixin[0]['key'], $weixin[0]['secret']); $menu_url = https://api.weixin.qq.com/cgi-bin/menu/create?access_token= . $accesstoken; return self::curlpost($jsonarray, $menu_url); } /* *客服消息回复 *@param array jsonarray array {touser:openid,msgtype:text,text:{content:hello world}} *@return string */ public function customservice($jsonarray, $hash) { if (empty($jsonarray)) { return false; } $db = m(); $sql = select * from bbc_wechats where hash=' . $hash . '; $wechast = $db->query($sql); $accesstoken = self::accesstoken($wechast[0]['key'], $wechast[0]['secret']); $tokenurl = https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token= . $accesstoken; $customres = self::curlpost($jsonarray, $tokenurl); return $customres; } /* *获取access_token *@return objectstr */ public function accesstoken($appid, $secret) { $access_token = bbccache::getcache('accesstoken' . $appid); if ($access_token) { $accesstokenret = $access_token; } else { $tookenurl = https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$appid}&secret={$secret}; $accesstokenres = @file_get_contents($tookenurl); $accesstoken = json_decode($accesstokenres); $accesstokenret = $accesstoken->access_token; bbccache::setcache('accesstoken' . $appid, $accesstoken->access_token, 3600); } return $accesstokenret; } /* *向远程接口post数据 *@data array {touser:openid,msgtype:text,text:{content:hello world}} *@return objectarray */ public function curlpost($data, $url) { $ch = curl_init(); curl_setopt($ch, curlopt_url, $url); curl_setopt($ch, curlopt_customrequest, post); curl_setopt($ch, curlopt_ssl_verifypeer, false); curl_setopt($ch, curlopt_ssl_verifyhost, false); curl_setopt($ch, curlopt_useragent, 'mozilla/5.0 (compatible; msie 5.01; windows nt 5.0)'); curl_setopt($ch, curlopt_followlocation, 1); curl_setopt($ch, curlopt_autoreferer, 1); curl_setopt($ch, curlopt_postfields, $data); curl_setopt($ch, curlopt_returntransfer, true); $info = curl_exec($ch); if (curl_errno($ch)) { echo 'errno' . curl_error($ch); } curl_close($ch); return json_decode($info); } //根据经纬度计算距离和方向 function getradian($d) { return $d * m_pi / 180; } function getdistance($lat1, $lng1, $lat2, $lng2) { $earth_radius = 6378.137; //地球半径 $lat1 = getradian($lat1); $lat2 = getradian($lat2); $a = $lat1 - $lat2; $b = getradian($lng1) - getradian($lng2); $v = 2 * asin(sqrt(pow(sin($a / 2) , 2) + cos($lat1) * cos($lat2) * pow(sin($b / 2) , 2))); $v = round($earth_radius * $v * 10000) / 10000; return $v; }}?>
教程网址:
欢迎收藏∩_∩但请保留本文链接。
其它类似信息

推荐信息