exit; } else { if ($type == "text") { $keyword = $msg->keyword; //用户输入的字符串 switch ($keyword) { case "红包拿来": /** * $api->responseText 用于输出微信要求的xml */ $tempMsg = "输入\"抢红包\",你懂的;输入\"剩余红包\"查询剩余红包个数。1000个红包已经到来!请关注我们的微博@BeeCloud,我们会持续不断发红包,会在新浪微博上发布红包消息的,请亲们关注~~"; echo $api->responseText($tempMsg); break; case "抢红包": $redpack = BCGetWxmpRedpack(); $raw = $api->sendRedpack($redpack); // $result = json_decode($raw); if (null == $result) { //发送失败 echo $api->responseText($redpackErrMsg); exit; } else { if ($result->resultCode == 0) { if ($result->sendStatus) { //发送成功 echo $api->responseText($redpackSuccessMsg); } else { if (preg_match("/^该用户已达到发送红包上限/", $result->sendMsg)) { echo $api->responseText($redpackRepeatMsg); } else {
//用户openId $appId = "c5d1cba1-5e3f-4ba0-941d-9b0a371fe719"; //BeeCloud appId !!!此处请用你的BeeCloud appId $appSecret = "39a7a518-9ac8-4a9e-87bc-7885f33cf18c"; //BeeCloud appSecret !!!此处请用你的BeeCloud appSecret $appSign = md5($appId . $appSecret); $mchId = "1234275402"; //微信商户号 !!!此处请用你的微信商户号 $api = new BCWxmpApi($appId, $appSecret, $mchId); $postStr = "<xml><ToUserName><![CDATA[gh_71e32cfe546c]]></ToUserName><FromUserName><![CDATA[o3kKrjlUsMnv__cK5DYZMl0JoAkY]]></FromUserName><CreateTime>1429494041</CreateTime><MsgType><![CDATA[text]]></MsgType><Content><![CDATA[抢红包]]></Content><MsgId>6139023951558013395</MsgId></xml>"; //在处理微信请求的服务器上请用如下方式获取真实xml //$postStr = $GLOBALS["HTTP_RAW_POST_DATA"]; $msg = $api->getCallMsg($postStr); //解析xml,获取msg内的参数 $redpack = array("nick_name" => "BeeCloud", "send_name" => "BeeCloud", "min" => 100, "max" => 105, "wishing" => "接入BeeCloud微信红包SDK,就可以实现发放微信红包功能,策划各种脑洞大开的粉丝活动啦!", "act_name" => "BeeCloud红包雨", "remark" => "BeeCloud", "count_per_user" => 100, "probability" => 0.3); echo $api->sendRedpack($redpack, 30); /** * 处理过程请参考以下 */ // // //$raw = $api->sendRedpack($redpack); //$result = json_decode($raw); //if (null == $result) { // //发送失败 // echo $api->responseText($redpackErrMsg); // exit(); //} else { // if ($result->resultCode == 0) { // if ($result->sendStatus) { // //发送成功