public function do_process() { global $_GP; $settings = globaSetting(); $sign = $_REQUEST["sign"]; $sign_type = $_REQUEST["sign_type"]; $biz_content = stripslashes($_REQUEST["biz_content"]); $service = $_REQUEST["service"]; $charset = $_REQUEST["charset"]; if (empty($sign) || empty($sign_type) || empty($biz_content) || empty($service) || empty($charset)) { echo "some parameter is empty."; exit; } $as = new AlipaySign(); $sign_verify = $as->rsaCheckV2($_REQUEST, $_GP['alipay_config']['alipay_public_key_file']); if (!$sign_verify) { if ($service == "alipay.service.check") { $EventType = $this->getNode2($biz_content, "EventType"); if ($EventType == "verifygw") { $as = new AlipaySign(); $response_xml = "<success>true</success><biz_content>" . $as->getPublicKeyStr($_GP['alipay_config']['merchant_public_key_file']) . "</biz_content>"; $return_xml = $as->sign_response($response_xml, $_GP['alipay_config']['charset'], $_GP['alipay_config']['merchant_private_key_file']); echo $return_xml; exit; } } else { echo "sign verfiy fail."; exit; } } if ($service == "alipay.service.check") { $EventType = $this->getNode2($biz_content, "EventType"); if ($EventType == "verifygw") { $as = new AlipaySign(); $response_xml = "<success>true</success><biz_content>" . $as->getPublicKeyStr($_GP['alipay_config']['merchant_public_key_file']) . "</biz_content>"; $return_xml = $as->sign_response($response_xml, 'GBK', $_GP['alipay_config']['merchant_private_key_file']); file_put_contents(WEB_ROOT . "/cache/1.log", $return_xml, FILE_APPEND); echo $return_xml; exit; } } if ($service == "alipay.mobile.public.message.notify") { $UserInfo = $this->getNode($biz_content, "UserInfo"); $FromUserId = $this->getNode($biz_content, "FromUserId"); $AppId = $this->getNode($biz_content, "AppId"); $CreateTime = $this->getNode($biz_content, "CreateTime"); $MsgType = $this->getNode($biz_content, "MsgType"); $EventType = $this->getNode($biz_content, "EventType"); $AgreementId = $this->getNode($biz_content, "AgreementId"); $ActionParam = $this->getNode($biz_content, "ActionParam"); $AccountNo = $this->getNode($biz_content, "AccountNo"); $text = $this->getNode($biz_content, "Text"); $push = new PushMsg(); if ($MsgType == "text" || $MsgType == "text" || $EventType == 'click') { $key = $text; if ($EventType == 'click') { $key = $ActionParam; } if (!empty($key)) { $reply = mysqld_select('SELECT * FROM ' . table('alipay_rule') . " WHERE keywords = :keywords", array(':keywords' => $key)); } } if ($EventType == 'follow') { $reply = mysqld_select('SELECT * FROM ' . table('alipay_rule') . " WHERE keywords = :keywords", array(':keywords' => subscribe_key)); } if (empty($reply['id'])) { $reply = mysqld_select('SELECT * FROM ' . table('alipay_rule') . " WHERE keywords = :keywords", array(':keywords' => default_key)); } if ($reply['ruletype'] == 1) { $reply['content'] = htmlspecialchars_decode($reply['description']); $reply['content'] = str_replace(array('<br>', ' '), array("\n", ' '), $reply['content']); $reply['content'] = strip_tags($reply['content'], '<a>'); $text_msg = $push->mkTextMsg($reply['content']); $biz_content = $push->mkTextBizContent($FromUserId, $text_msg); $return_msg = $push->sendRequest($biz_content); file_put_contents(WEB_ROOT . "/cache/2.log", $biz_content . '|' . $return_msg, FILE_APPEND); } if ($reply['ruletype'] == 2) { $reply['content'] = htmlspecialchars_decode($reply['description']); $reply['content'] = str_replace(array('<br>', ' '), array("\n", ' '), $reply['content']); $reply['content'] = strip_tags($reply['content'], '<a>'); //WEBSITE_ROOT.'attachment/'.$reply['thumb'] $image_text_msg1 = $push->mkImageTextMsg($reply['title'], $reply['content'], $reply['url'], WEBSITE_ROOT . 'attachment/' . $reply['thumb'], "loginAuth"); $image_text_msg = array($image_text_msg1); $biz_content = $push->mkImageTextBizContent($FromUserId, $image_text_msg); $return_msg = $push->sendRequest($biz_content); file_put_contents(WEB_ROOT . "/cache/1.log", $biz_content, FILE_APPEND); } echo $this->mkAckMsg($FromUserId); exit; // file_put_contents ( WEB_ROOT . "/cache/1.log",$x , FILE_APPEND ); } }
public function Message($biz_content, $FuwuToken) { $UserInfo = $this->getNode($biz_content, 'UserInfo'); $FromUserId = $this->getNode($biz_content, 'FromUserId'); $AppId = $this->getNode($biz_content, 'AppId'); $CreateTime = $this->getNode($biz_content, 'CreateTime'); $Content = $this->getNode($biz_content, 'Content'); $MsgType = $this->getNode($biz_content, 'MsgType'); $EventType = $this->getNode($biz_content, 'EventType'); $AgreementId = $this->getNode($biz_content, 'AgreementId'); $ActionParam = $this->getNode($biz_content, 'ActionParam'); $AccountNo = $this->getNode($biz_content, 'AccountNo'); $push = new PushMsg(); if ($EventType) { switch ($EventType) { case 'click': $et = ''; $Content = $ActionParam; $etkey = ''; break; case 'enter': $ap = json_decode($ActionParam, true); if ($ap['scene']['sceneId'] != '') { $et = 'SCAN'; $ap = json_decode($ActionParam, true); $etkey = $ap['scene']['sceneId']; } else { exit('error'); } break; default: $et = 'subscribe'; $etkey = ''; break; } } $ApiData = array('ali' => 1, 'token' => $FuwuToken, 'eventType' => $et, 'fromUserName' => $FromUserId, 'keyword' => $Content, 'EventKey' => $etkey); $weixin = new WeixinAction(); $rt2 = $weixin->index($ApiData); if ($rt2[1] == 'text') { $text_msg = $push->mkTextMsg($rt2[0]); $biz_content = $push->mkTextBizContent($FromUserId, $text_msg); $return_msg = $push->sendRequest($biz_content); } else { if ($rt2[1] == 'news') { $image_text_msg = array(); foreach ($rt2[0] as $news) { $searchArr = array('微信'); $replaceArr = array('支付宝服务窗'); $news[0] = str_replace($searchArr, $replaceArr, $news[0]); $news[1] = str_replace($searchArr, $replaceArr, $news[1]); $linkUrl = $news[3]; $urlInfos = parse_url($linkUrl); $p1 = explode('&', $urlInfos['query']); $params = array(); foreach ($p1 as $p1item) { $p2 = explode('=', $p1item); if ($p2[0] != 'wecha_id') { $params[$p2[0]] = $p2[1]; } } $parmsStr = ''; $andStr = ''; $params['wecha_id'] = 'z_' . md5($FromUserId); $params['ali'] = 1; foreach ($params as $pk => $pv) { $parmsStr .= $andStr . $pk . '=' . $pv; $andStr = '&'; } $linkUrlArr = explode('?', $linkUrl); $linkUrl = $linkUrlArr[0] . '?' . $parmsStr; $a = $push->mkImageTextMsg($news[0], $news[1], $linkUrl, $news[2], 'loginAuth'); array_push($image_text_msg, $a); } $biz_content = $push->mkImageTextBizContent($FromUserId, $image_text_msg); $return_msg = $push->sendMsgRequest($biz_content); } else { $text_msg = $push->mkTextMsg($rt2[0] . 'zz'); $biz_content = $push->mkTextBizContent($FromUserId, $text_msg); $return_msg = $push->sendRequest($biz_content); } } }
function C10Pr($biz_content) { require './Wxin_V10C_150513/Doc/fuwuchuang/PushMsg.php'; header("Content-Type: text/xml;charset=GBK"); writeLog($biz_content); $UserInfo = $this->getNode($biz_content, "UserInfo"); $FromUserId = $this->getNode($biz_content, "FromUserId"); $AppId = $this->getNode($biz_content, "AppId"); $CreateTime = $this->getNode($biz_content, "CreateTime"); $MsgType = $this->getNode($biz_content, "MsgType"); $EventType = $this->getNode($biz_content, "EventType"); $AgreementId = $this->getNode($biz_content, "AgreementId"); $ActionParam = $this->getNode($biz_content, "ActionParam"); $AccountNo = $this->getNode($biz_content, "AccountNo"); $push = new PushMsg(); // 收到用户发送的对话消息 if ($MsgType == "text") { $text = $this->getNode($biz_content, "Text"); writeLog("收到的文本:" . $text); $text_msg = $push->mkTextMsg("你好,这是对话消息"); // 发给这个关注的用户 $biz_content = $push->mkTextBizContent($FromUserId, $text_msg); $biz_content = iconv("UTF-8", "GBK//IGNORE", $biz_content); writeLog(iconv("UTF-8", "GBK", "\r\n发送的biz_content:" . $biz_content)); // $return_msg = $push->sendMsgRequest ( $biz_content ); $return_msg = $push->sendRequest($biz_content); // 日志记录 writeLog("发送对话消息返回:" . $return_msg); } // 接收用户发送的 图片消息 if ($MsgType == "image") { $mediaId = $this->getNode($biz_content, "MediaId"); $format = $this->getNode($biz_content, "Format"); $biz_content = "{\"mediaId\":\"" . $mediaId . "\"}"; $fileName = realpath("img") . "/{$mediaId}.{$format}"; // 下载保存图片 $push->downMediaRequest($biz_content, $fileName); writeLog("收到的图片路径:" . $fileName); $text_msg = $push->mkTextMsg("你好,图片已接收。"); // 发给这个关注的用户 $biz_content = $push->mkTextBizContent($FromUserId, $text_msg); $biz_content = iconv("UTF-8", "GBK//IGNORE", $biz_content); writeLog(iconv("UTF-8", "GBK", "\r\n发送的biz_content:" . $biz_content)); // $return_msg = $push->sendMsgRequest ( $biz_content ); $return_msg = $push->sendRequest($biz_content); // 日志记录 writeLog("发送对话消息返回:" . $return_msg); } // 收到用户发送的关注消息 if ($EventType == "follow") { // 处理关注消息 // 一般情况下,可推送一条欢迎消息或使用指导的消息。 // 如: $image_text_msg1 = $push->mkImageTextMsg("标题,感谢关注", "描述", "http://wap.taobao.com", "https://i.alipayobjects.com/e/201310/1H9ctsy9oN_src.jpg", "loginAuth"); $image_text_msg2 = $push->mkImageTextMsg("标题", "描述", "http://wap.taobao.com", "https://i.alipayobjects.com/e/201310/1H9ctsy9oN_src.jpg", "loginAuth"); // 组装多条图文信息 $image_text_msg = array($image_text_msg1, $image_text_msg2); // 发给这个关注的用户 $biz_content = $push->mkImageTextBizContent($FromUserId, $image_text_msg); $return_msg = $push->sendRequest($biz_content); // 日志记录 file_put_contents("log.txt", $return_msg . "\r\n", FILE_APPEND); } elseif ($EventType == "unfollow") { // 处理取消关注消息 } elseif ($EventType == "enter") { // 处理进入消息,扫描二维码进入,获取二维码扫描传过来的参数 $arr = json_decode($ActionParam); if ($arr != null) { writeLog("二维码传来的参数:" . var_export($arr, true)); $sceneId = $arr->scene->sceneId; writeLog("二维码传来的参数,场景ID:" . $sceneId); // 这里可以根据定义场景ID时指定的规则,来处理对应事件。 // 如:跳转到某个页面,或记录从什么来源(哪种宣传方式)来关注的本服务窗 } // 处理关注消息 // 一般情况下,可推送一条欢迎消息或使用指导的消息。 // 如: $image_text_msg1 = $push->mkImageTextMsg("标题,进入服务窗", "描述:进入服务窗", "http://wap.taobao.com", "", "loginAuth"); // $image_text_msg2 = $push->mkImageTextMsg ( "标题", "描述", "http://wap.taobao.com", "https://i.alipayobjects.com/e/201310/1H9ctsy9oN_src.jpg", "loginAuth" ); // 组装多条图文信息 $image_text_msg = array($image_text_msg1); // 发给这个关注的用户 $biz_content = $push->mkImageTextBizContent($FromUserId, $image_text_msg); $return_msg = $push->sendRequest($biz_content); // 日志记录 writeLog("发送消息返回:" . var_export($return_msg, true)); } elseif ($EventType == "click") { // 处理菜单点击的消息 // 在服务窗后台配置一个菜单,菜单类型为调用服务,菜单参数为sendmsg,用户点击次菜单后,就会调用到这里 if ($ActionParam == "sendmsg") { $image_text_msg1 = $push->mkImageTextMsg("标题,发送消息测试", "描述:发送消息测试", "http://wap.taobao.com", "", "loginAuth"); // 组装多条图文信息 $image_text_msg = array($image_text_msg1); // 发给这个关注的用户 $biz_content = $push->mkImageTextBizContent($FromUserId, $image_text_msg); $return_msg = $push->sendRequest($biz_content); // 日志记录 writeLog("发送消息返回:" . var_export($return_msg, true)); } } // 给支付宝返回ACK回应消息,不然支付宝会再次重试发送消息,再调用此方法之前,不要打印输出任何内容 echo self::mkAckMsg($FromUserId); exit; }