public function problem()
 {
     $post = I('post.');
     addWeixinLog($post, '[微信告警接口]');
     LogRecord(serialize($post), '[微信告警接口]');
     echo "";
 }
 public function index()
 {
     // 删除微信传递的token干扰
     unset($_REQUEST['token']);
     $weixin = D('Weixin');
     // 获取数据
     $data = $weixin->getData();
     $this->data = $data;
     if (!empty($data['ToUserName'])) {
         get_token($data['ToUserName']);
     }
     if (!empty($data['FromUserName'])) {
         get_openid($data['FromUserName']);
     }
     $this->token = $data['ToUserName'];
     // 记录日志
     addWeixinLog($data, $GLOBALS['HTTP_RAW_POST_DATA']);
     // 初始化用户
     $data['ToUserName'] == 'gh_3c884a361561' || $this->init_follow($data);
     // 回复数据
     $this->reply($data, $weixin);
     // 客服接口群发消息:未发送成功的消息给用户重新发
     $this->sendOldMessage($data['ToUserName'], $data['FromUserName']);
     // 结束程序。防止oneThink框架的调试信息输出
     exit;
 }
 private function _dealWeixinPost()
 {
     $content = wp_file_get_contents('php://input');
     vendor('WXBiz.wxBizMsgCrypt');
     $this->sReqTimeStamp = I('get.timestamp');
     $this->sReqNonce = I('get.nonce');
     $this->sEncryptMsg = I('get.msg_signature');
     $this->wxcpt = new \WXBizMsgCrypt('weiphp', '0c79e1fa963cd80cc0be99b20a18faeb', 'wx2685aca90abe2895');
     $sMsg = "";
     // 解析之后的明文
     $errCode = $this->wxcpt->DecryptMsg($this->sEncryptMsg, $this->sReqTimeStamp, $this->sReqNonce, $content, $sMsg);
     if ($errCode != 0) {
         addWeixinLog($_GET, "DecryptMsg Error: " . $errCode);
         return false;
     } else {
         // 解密成功,sMsg即为xml格式的明文
         $content = $sMsg;
     }
     $data = new \SimpleXMLElement($content);
     // $data || die ( '参数获取失败' );
     foreach ($data as $key => $value) {
         $this->data[$key] = safe(strval($value));
     }
     return $data;
 }
 function init_follow($openid, $token = '', $has_subscribe = false)
 {
     empty($token) && ($token = get_token());
     addWeixinLog($openid . '::_' . $token, 'init_follow_in');
     if (empty($openid) || $openid == -1 || empty($token) || $token == -1) {
         return false;
     }
     $data['token'] = $token;
     $data['openid'] = $openid;
     $datas = $data;
     $uid = M('public_follow')->where($data)->getField('uid');
     addWeixinLog($uid, 'init_follow_check_uid');
     if ($uid) {
         return $uid;
     }
     // 自动注册
     $config = getAddonConfig('UserCenter', $token);
     $user = array('experience' => intval($config['experience']), 'score' => intval($config['score']), 'reg_ip' => get_client_ip(1), 'reg_time' => NOW_TIME, 'last_login_ip' => get_client_ip(1), 'last_login_time' => NOW_TIME, 'status' => 1, 'is_init' => 1, 'is_audit' => 1, 'come_from' => 1);
     $user2 = getWeixinUserInfo($openid);
     $user = array_merge($user, $user2);
     $data['uid'] = $uid = D('Common/User')->add($user);
     if ($has_subscribe !== false) {
         $data['has_subscribe'] = $has_subscribe;
     }
     M('public_follow')->add($data);
     return $uid;
 }
 function setTicket()
 {
     include_once ONETHINK_ADDON_PATH . 'PublicBind/wxBizMsgCrypt.php';
     // 第三方发送消息给公众平台
     $encodingAesKey = 'DfEqNBRvzbg8MJdRQCSGyaMp6iLcGOldKFT0r8I6Tnp';
     $token = 'weiphp';
     $appId = D('Addons://PublicBind/PublicBind')->component_appid;
     $timeStamp = empty($_GET['timestamp']) ? "" : trim($_GET['timestamp']);
     $nonce = empty($_GET['nonce']) ? "" : trim($_GET['nonce']);
     $msg_sign = empty($_GET['msg_signature']) ? "" : trim($_GET['msg_signature']);
     $encryptMsg = file_get_contents('php://input');
     $pc = new \WXBizMsgCrypt($token, $encodingAesKey, $appId);
     // 第三方收到公众号平台发送的消息
     $msg = '';
     $errCode = $pc->decryptMsg($msg_sign, $timeStamp, $nonce, $encryptMsg, $msg);
     if ($errCode == 0) {
         $data = $this->_xmlToArr($msg);
         $map['name'] = 'PublicBind';
         $config = M('addons')->where($map)->getField('config');
         $config = (array) json_decode($config, true);
         $config['ComponentVerifyTicket'] = $data['ComponentVerifyTicket'];
         $save['config'] = json_encode($config);
         M('addons')->where($map)->save($save);
         echo 'success';
     } else {
         addWeixinLog('解密后失败:' . $errCode, 'setTicket_error');
     }
 }
 function reply($dataArr, $keywordArr = array())
 {
     $config = getAddonConfig('Juhe');
     // 获取后台插件的配置参数
     if ($keywordArr['keyword'] == '股票') {
         if ($dataArr['Content'] == $keywordArr['keyword']) {
             set_user_status('Juhe', $keywordArr);
             $this->replyText('请输入股票编号,上海股市以sh开头,深圳股市以sz开头如:sh601009');
         } else {
             $url = 'http://web.juhe.cn:8080/finance/stock/hs?gid=' . $dataArr['Content'] . '&key=' . $config['stock'];
             $content = file_get_contents($url);
             $content = json_decode($content, true);
             $content = $content['result'][0]['dapandata'];
             if (empty($content)) {
                 $this->replyText('股票编号不对');
                 return false;
             }
             $str = "名称: " . $content['name'] . "\n当前点数: " . $content['dot'] . "\n当前价格: " . $content['nowPic'] . "\n涨跌率: " . $content['rate'] . "\n成交量: " . $content['traNumber'] . "手\n成交金额: " . $content['traAmount'] . "万元\r\n";
             $str .= '如需查询其它股票,请在菜单再次点击"股票查询"重新进入查询';
             $this->replyText($str);
         }
     } elseif ($keywordArr['keyword'] == '黄金') {
         if ($dataArr['Content'] == $keywordArr['keyword']) {
             $url = 'http://web.juhe.cn:8080/finance/gold/shgold?key=' . $config['gold'];
             $content = file_get_contents($url);
             addWeixinLog($content, $url);
             $content = json_decode($content, true);
             $keywordArr['content'] = $content['result'][0];
             $str = "请输入以下列表前的编号查询,如要查询品种为 Ag(T+D)的情况,回复:1\r\n";
             $accept['type'] = 'array';
             foreach ($keywordArr['content'] as $key => $vo) {
                 $str .= $key . ': ' . $vo['variety'] . "\n";
                 $accept['data'][] = $key;
             }
             $keywordArr['accept'] = $accept;
             set_user_status('Juhe', $keywordArr);
             $this->replyText($str);
         } else {
             $vo = $keywordArr['content'][$dataArr['Content']];
             $str = "品种: " . $vo['variety'] . "\n最新价: " . $vo['latestpri'] . "\n开盘价: " . $vo['openpri'] . "\n最高价: " . $vo['maxpri'] . "\n最低价: " . $vo['minpri'] . "\n涨跌幅: " . $vo['limit'] . "\n昨收价: " . $vo['yespri'] . "\n总成交量: " . $vo['totalvol'] . "\r\n";
             $str .= '如需查询其它黄金品种,请在菜单再次点击"黄金数据"重新进入查询';
             $this->replyText($str);
         }
     } elseif ($keywordArr['keyword'] == '货币汇率') {
         $url = 'http://web.juhe.cn:8080/finance/exchange/rmbquot?key=' . $config['exchange'];
         $content = file_get_contents($url);
         $content = json_decode($content, true);
         $content = $content['result'][0];
         $str = "货币 : 中间价\r\n";
         foreach ($content as $vo) {
             $str .= $vo['name'] . ' :' . $vo['bankConversionPri'] . "\n";
         }
         $this->replyText($str);
     }
 }
 public function sendtempmsg($openid, $template_id, $url, $data, $topcolor = '#FF0000')
 {
     $xml = '{"touser":"******","template_id":"' . $template_id . '","url":"' . $url . '","topcolor":"' . $topcolor . '","data":' . $data . '}';
     $res = $this->curlPost('https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=' . get_access_token(), $xml);
     $res = json_decode($res, true);
     // 记录日志
     if ($res['errcode'] == 0) {
         addWeixinLog($xml, 'post');
     }
     $senddata = array('openid' => $openid, 'template_id' => $template_id, 'MsgID' => $res['msgid'], 'message' => $data, 'sendstatus' => $res['errcode'] == 0 ? 0 : 1, 'token' => get_token(), 'ctime' => time());
     M('tmplmsg')->add($senddata);
     return $res;
 }
Example #8
0
 public function index()
 {
     $this->token = get_token();
     $weixin = D('Weixin');
     // 获取数据
     $data = $weixin->getData();
     if (!empty($data['FromUserName'])) {
         session('openid', $data['FromUserName']);
     }
     // 记录日志
     addWeixinLog($data, $GLOBALS['HTTP_RAW_POST_DATA']);
     // 回复数据
     $this->reply($data);
 }
 public function NotifyProcess($data, &$msg)
 {
     $notfiyOutput = array();
     if (!array_key_exists("transaction_id", $data)) {
         $msg = "输入参数不正确";
         return false;
     }
     //查询订单,判断订单真实性
     //		if(!$this->Queryorder($data["transaction_id"])){
     //			$msg = "订单查询失败";
     //			return false;
     //		}
     //支付成功通知地址
     //		$url = "http://2test.8raw.com/index.php/Shop/WxpayNotify/aysncNotify?key=hebidu";
     $url = $this->config['PROCESS_URL'];
     addWeixinLog(json_encode($data), "[成功通知处理数据结构]");
     $entity = array();
     fsockopenRequest($url, $data);
     //TODO: 异步处理流程
     //	<xml><appid><![CDATA[wx5f9ed360f5da5370]]></appid>
     //<attach><![CDATA[13_]]></attach>
     //<bank_type><![CDATA[CFT]]></bank_type>
     //<cash_fee><![CDATA[1]]></cash_fee>
     //<fee_type><![CDATA[CNY]]></fee_type>
     //<is_subscribe><![CDATA[Y]]></is_subscribe>
     //<mch_id><![CDATA[1238878502]]></mch_id>
     //<nonce_str><![CDATA[lgejoe9g234qsz67lwk5qhoafv4nuvz9]]></nonce_str>
     //<openid><![CDATA[oxGH0sgeUkH4g8aowy0452xJnX1o]]></openid>
     //<out_trade_no><![CDATA[2015042820173392481208_2]]></out_trade_no>
     //<result_code><![CDATA[SUCCESS]]></result_code>
     //<return_code><![CDATA[SUCCESS]]></return_code>
     //<sign><![CDATA[1DFD346C8F496CCC7D45CF7031B0257C]]></sign>
     //<time_end><![CDATA[20150428201758]]></time_end>
     //<total_fee>1</total_fee>
     //<trade_type><![CDATA[JSAPI]]></trade_type>
     //<transaction_id><![CDATA[1009360424201504280096239638]]></transaction_id>
     //</xml>
     return true;
 }
 public function index()
 {
     //删除微信传递的token干扰
     unset($_REQUEST['token']);
     $weixin = D('Weixin');
     // 获取数据
     $data = $weixin->getData();
     if (!empty($data['ToUserName'])) {
         get_token($data['ToUserName']);
     }
     if (!empty($data['FromUserName'])) {
         session('openid', $data['FromUserName']);
     }
     $this->token = $data['ToUserName'];
     $this->initFollow($weixin);
     // 记录日志
     addWeixinLog($data, $GLOBALS['HTTP_RAW_POST_DATA']);
     // 回复数据
     $this->reply($data, $weixin);
     // 结束程序。防止oneThink框架的调试信息输出
     exit;
 }
 /**
  * 订单保存
  */
 public function save()
 {
     //收货地址ID
     $address_id = I('post.address_id', 0);
     $province_name = I('post.province_name', '');
     $city_name = I('post.city_name', '');
     $area_name = I('post.area_name', '');
     $notes = I('post.notes', array());
     $userinfo = $this->userinfo;
     if (IS_POST && is_array($userinfo)) {
         addWeixinLog($userinfo, '[session]saveispost');
         //购买的商品的列表
         $buyProductList = session("confirm_order_info");
         if (empty($buyProductList)) {
             $this->error("您尚未选购商品!");
         }
         addWeixinLog($buyProductList, '购买商品的列表');
         $map = array('id' => $address_id);
         $result = apiCall(AddressApi::GET_INFO, array($map));
         if (!$result['status']) {
             $this->error($result['info']);
         }
         if (is_null($result['info'])) {
             LogRecord("收货地址信息获取失败", __FILE__ . __LINE__);
             //如果是空的
             $this->error("收货地址信息获取失败!");
         }
         $address_info = $result['info'];
         //总价,不含运费
         $all_price = $buyProductList['all_price'];
         //运费
         $all_express = $buyProductList['all_express'];
         //订单对象
         $entity = array('wxaccountid' => $this->wxaccount['id'], 'storeid' => 0, 'wxuser_id' => $userinfo['id'], 'price' => 0, 'mobile' => $address_info['mobile'], 'wxno' => $address_info['wxno'], 'contactname' => $address_info['contactname'], 'note' => '', 'country' => $address_info['country'], 'province' => $province_name, 'city' => $city_name, 'area' => $area_name, 'detailinfo' => $address_info['detailinfo'], 'orderid' => '', 'items' => '');
         $i = 0;
         $ids = '';
         $orderid = $this->getOrderID();
         //			addWeixinLog($buyProductList['list'],'订单');
         //分店铺保存订单,每个店铺一张订单
         foreach ($buyProductList['list'] as $key => $vo) {
             //店铺ID
             $entity['storeid'] = $key;
             $entity['orderid'] = $orderid . '_' . $key;
             $entity['items'] = $vo;
             //
             $price = 0.0;
             foreach ($vo['products'] as $item) {
                 //					addWeixinLog($item,'订单[test]');
                 $price += $item['price'] * intval($item['count']);
             }
             $entity['price'] = $price;
             if ($i < count($notes)) {
                 $entity['note'] = $notes[$i];
             }
             $i++;
             //				dump($entity['items']['products']);
             //				exit();
             //dump($entity);
             $result = apiCall(OrdersApi::ADD_ORDER, array($entity));
             //				addWeixinLog($result,'订单3333');
             if (!$result['status']) {
                 LogRecord($result['info'], __FILE__ . __LINE__);
                 $this->error($result['info']);
             }
             $ids .= $result['info'] . '-';
         }
         $ids = trim($ids, "-");
         //TODO: 从购物车中移除相对应的商品,根据店铺ID,商品ID,商品SKU
         //目前 就直接删除购物车
         session("shoppingcart", null);
         session("confirm_order_info", null);
         $this->success("订单保存成功,前往支付!", C('SITE_URL') . "/index.php/Shop/Pay/pay/id/{$ids}?showwxpaytitle=1");
     } else {
         LogRecord("禁止访问!", __FILE__ . __LINE__);
         $this->error("禁止访问!");
     }
 }
 /**
  * 
  * 1. 订单[已收货]-》检测 time() - updatetime > 指定时间,暂定15天 满足条件变更为订单[已收货]
  */
 private function toCompleted()
 {
     $interval = 24 * 3600 * 15;
     //15天
     $result = apiCall("Tool/Orders/orderStatusToCompleted", array($interval));
     if (!$result['status']) {
         LogRecord($result['info'], __FILE__ . __LINE__);
     } else {
         if ($result['info'] > 0) {
             addWeixinLog("更新订单为已完成影响记录数:" . $result['info'], '3');
         }
     }
 }
 private function sendToWxaccount($wxaccountid, $text)
 {
     $result = apiCall(WxaccountApi::GET_INFO, array(array('id' => $wxaccountid)));
     if ($result['status']) {
         $wxapi = new WeixinApi($result['info']['appid'], $result['info']['appsecret']);
         $map = array('name' => "WXPAY_OPENID");
         $result = apiCall(ConfigApi::GET_INFO, array($map));
         addWeixinLog($result, "接收订单支付成功的OPENID");
         if ($result['status']) {
             $openidlist = explode(",", $result['info']['value']);
             foreach ($openidlist as $openid) {
                 $wxapi->sendTextToFans($openid, $text);
             }
         }
     } else {
         LogRecord($result['info'], __FILE__ . __LINE__ . "发送支付成功消息失败");
     }
 }
 /**
  * 微信支付页面
  */
 public function pay()
 {
     //订单ID
     $ids = I('get.id', 0);
     //
     $ids = rtrim($ids, "-");
     $ids_arr = explode("-", $ids);
     if (count($ids_arr) == 0) {
         $this->error("参数错误!");
     }
     $map = array();
     $map['id'] = array('in', $ids_arr);
     $result = apiCall(OrdersInfoViewApi::QUERY_NO_PAGING, array($map));
     //TODO: 判断订单状态是否为待支付
     // dump($result['status']);
     if ($result['status']) {
         $order_list = $result['info'];
         $payConfig = C('WXPAY_CONFIG');
         $payConfig['jsapicallurl'] = getCurrentURL();
         //dump($payConfig);
         addWeixinLog($payConfig, "配置信息");
         $items = array();
         $total_fee = 0;
         $total_express = 0.0;
         $body = "";
         $attach = "";
         foreach ($order_list as $order) {
             $trade_no = $order['orderid'];
             $total_fee += $order['price'];
             $order_express = 0;
             $products = $this->getProducts($order[id]);
             foreach ($products as $vo) {
                 if ($order_express < $vo['post_price']) {
                     $order_express = $vo['post_price'];
                 }
                 if (empty($body)) {
                     $body = $vo['name'];
                 }
             }
             $total_express += $order_express;
             $attach .= $order['id'] . '_';
             array_push($items, $item);
         }
         $dnotNeedPostPrice = C('DNOT_NEED_POST_PRICE');
         $dnotNeedPostPrice = floatval($dnotNeedPostPrice);
         if (floatval($total_fee) >= $dnotNeedPostPrice * 100.0) {
             $total_express = 0;
         }
         //            dump($total_fee);
         //            dump($total_express);
         $total_fee = $total_fee + $total_express;
         if ($total_fee <= 0) {
             $this->error("支付金额不能小于0!");
         }
         if (APP_DEBUG) {
             //			    $total_fee = 1;
         }
         if (empty($body)) {
             $body = date("Y-m-d", time()) . "购买商品";
         }
         $body = mb_substr($body, 0, 31, 'utf-8');
         //测试时
         $this->setWxpayConfig($payConfig, $trade_no, $body, $total_fee, $attach);
         //dump($payConfig);
         $this->assign("total_express", $total_express);
         $this->assign("ids", I('get.id', 0));
         $this->assign("total_fee", $total_fee);
         $this->theme($this->themeType)->display();
     } else {
         $this->error("支付失败!");
     }
 }
Example #15
0
 /**
  * 微信消息接口入口
  * 所有发送到微信的消息都会推送到该操作
  * 所以,微信公众平台后台填写的api地址则为该操作的访问地址
  * 在mp.weixin.qq.com 开发者中心配置的 URL(服务器地址)  http://域名/index.php/home/weixin/index/id/member_public表的id.html
  */
 public function index()
 {
     $this->WX->valid();
     $type = $this->WX->getRev()->getRevType();
     if (C('DEVELOP_MODE')) {
         addWeixinLog($GLOBALS['HTTP_RAW_POST_DATA']);
     }
     //与微信交互的中控服务器逻辑可以自己定义,这里实现一个通用的
     switch ($type) {
         //事件
         case TPWechat::MSGTYPE_EVENT:
             //先处理事件型消息
             $event = $this->WX->getRevEvent();
             switch ($event['event']) {
                 //关注l
                 case TPWechat::EVENT_SUBSCRIBE:
                     //二维码关注
                     if (isset($event['eventkey']) && isset($event['ticket'])) {
                     } else {
                         //普通关注
                     }
                     $openid = $this->WX->getRevFrom();
                     $User = M('User');
                     $user_info = $User->where(array('openid' => $openid))->find();
                     if ($user_info) {
                         $map = array('openid' => $this->WX->getRevFrom());
                         $User->where($map)->setField('is_subscribe', 1);
                     } else {
                         $wx_info = $this->WX->getUserInfo($this->WX->getRevFrom());
                         $wx_info['nickname'] = remove_emoji($wx_info['nickname']);
                         $data = array('openid' => $openid, 'user_name' => $wx_info['nickname'], 'user_avatar' => $wx_info['headimgurl'], 'is_subscribe' => 1, 'status' => 1, 'create_time' => NOW_TIME, 'update_time' => NOW_TIME);
                         $User->add($data);
                     }
                     $this->WX->text(html_entity_decode(C('SUBSCRIBE_MSG')))->reply();
                     break;
                     //扫描二维码
                 //扫描二维码
                 case TPWechat::EVENT_SCAN:
                     break;
                     //地理位置
                 //地理位置
                 case TPWechat::EVENT_LOCATION:
                     break;
                     //自定义菜单 - 点击菜单拉取消息时的事件推送
                 //自定义菜单 - 点击菜单拉取消息时的事件推送
                 case TPWechat::EVENT_MENU_CLICK:
                     switch ($event['key']) {
                         case 'MENU_KEY_NEWS':
                             break;
                         default:
                             # code...
                             break;
                     }
                     break;
                     //自定义菜单 - 点击菜单跳转链接时的事件推送
                 //自定义菜单 - 点击菜单跳转链接时的事件推送
                 case TPWechat::EVENT_MENU_VIEW:
                     $this->WX->text('//自定义菜单 - 点击菜单跳转链接时的事件推送')->reply();
                     break;
                     //自定义菜单 - 扫码推事件的事件推送
                 //自定义菜单 - 扫码推事件的事件推送
                 case TPWechat::EVENT_MENU_SCAN_PUSH:
                     break;
                     //自定义菜单 - 扫码推事件且弹出“消息接收中”提示框的事件推送
                 //自定义菜单 - 扫码推事件且弹出“消息接收中”提示框的事件推送
                 case TPWechat::EVENT_MENU_SCAN_WAITMSG:
                     break;
                     //自定义菜单 - 弹出系统拍照发图的事件推送
                 //自定义菜单 - 弹出系统拍照发图的事件推送
                 case TPWechat::EVENT_MENU_PIC_SYS:
                     break;
                     //自定义菜单 - 弹出拍照或者相册发图的事件推送
                 //自定义菜单 - 弹出拍照或者相册发图的事件推送
                 case TPWechat::EVENT_MENU_PIC_PHOTO:
                     break;
                     //自定义菜单 - 弹出微信相册发图器的事件推送
                 //自定义菜单 - 弹出微信相册发图器的事件推送
                 case TPWechat::EVENT_MENU_PIC_WEIXIN:
                     break;
                     //自定义菜单 - 弹出地理位置选择器的事件推送
                 //自定义菜单 - 弹出地理位置选择器的事件推送
                 case TPWechat::EVENT_MENU_LOCATION:
                     break;
                     //取消关注
                 //取消关注
                 case TPWechat::EVENT_UNSUBSCRIBE:
                     $openid = $this->WX->getRevFrom();
                     $User = M('User');
                     $user_info = $User->where(array('openid' => $openid))->find();
                     if ($user_info) {
                         $map = array('openid' => $this->WX->getRevFrom());
                         $User->where($map)->setField('is_subscribe', 0);
                     } else {
                         $wx_info = $this->WX->getUserInfo($this->WX->getRevFrom());
                         $data = array('openid' => $openid, 'user_name' => $wx_info['nickname'], 'user_avatar' => $wx_info['headimgurl'], 'is_subscribe' => 0, 'status' => 1, 'create_time' => NOW_TIME, 'update_time' => NOW_TIME);
                         $User->add($data);
                     }
                     break;
                     //群发接口完成后推送的结果
                 //群发接口完成后推送的结果
                 case TPWechat::EVENT_SEND_MASS:
                     break;
                     //模板消息完成后推送的结果
                 //模板消息完成后推送的结果
                 case TPWechat::EVENT_SEND_TEMPLATE:
                     break;
                 default:
                     break;
             }
             break;
             //文本
         //文本
         case TPWechat::MSGTYPE_TEXT:
             $keyword = trim($this->WX->getRevContent());
             switch ($keyword) {
                 case '1':
                     $this->WX->text(html_entity_decode(C('SUBSCRIBE_MSG')))->reply();
                     break;
                 case '2':
                     $data = array(array('Title' => '最新新闻', 'Description' => '测试description1', 'PicUrl' => 'http://shop.zlsgx.com/images/201508/goods_img/3_G_1440030087739.jpg', 'Url' => ''), array('Title' => '最新新闻', 'Description' => '测试description2', 'PicUrl' => 'http://shop.zlsgx.com/images/201508/goods_img/5_G_1440028482068.jpg', 'Url' => ''), array('Title' => '最新新闻', 'Description' => '测试description3', 'PicUrl' => 'http://shop.zlsgx.com/images/201508/goods_img/5_G_1440028482068.jpg', 'Url' => ''), array('Title' => '最新新闻', 'Description' => '测试description4', 'PicUrl' => 'http://shop.zlsgx.com/images/201508/goods_img/5_G_1440028482068.jpg', 'Url' => ''));
                     $this->WX->news($data)->reply();
                     break;
                 default:
                     //$this->WX->text("默认信息...")->reply();
                     //接入客服
                     $this->WX->transfer_customer_service()->reply();
                     break;
             }
             break;
             //图像
         //图像
         case TPWechat::MSGTYPE_IMAGE:
             break;
             //语音
         //语音
         case TPWechat::MSGTYPE_VOICE:
             break;
             //视频
         //视频
         case TPWechat::MSGTYPE_VIDEO:
             break;
             //位置
         //位置
         case TPWechat::MSGTYPE_LOCATION:
             break;
             //链接
         //链接
         case TPWechat::MSGTYPE_LINK:
             break;
         default:
             break;
     }
 }
 private function _replyData($msg, $msgType)
 {
     $msg['ToUserName'] = $this->data['FromUserName'];
     $msg['FromUserName'] = $this->data['ToUserName'];
     $msg['CreateTime'] = NOW_TIME;
     $msg['MsgType'] = $msgType;
     if ($_REQUEST['doNotInit']) {
         dump($msg);
         exit;
     }
     $xml = new \SimpleXMLElement('<xml></xml>');
     $this->_data2xml($xml, $msg);
     $str = $xml->asXML();
     // 记录日志
     addWeixinLog($str, '_replyData');
     if ($_GET['encrypt_type'] == 'aes') {
         $sEncryptMsg = "";
         // xml格式的密文
         $errCode = $this->wxcpt->EncryptMsg($str, $this->sReqTimeStamp, $this->sReqNonce, $sEncryptMsg);
         if ($errCode == 0) {
             $str = $sEncryptMsg;
         } else {
             addWeixinLog($str, "EncryptMsg Error: " . $errCode);
         }
     }
     echo $str;
 }
 /**
  *
  * @param $entity | key=》username,password ,from . email,mobile非必须
  * @return array
  */
 public function register($entity)
 {
     if (!isset($entity['username']) || !isset($entity['password']) || !isset($entity['from'])) {
         return array('status' => false, 'info' => "账户信息缺失!");
     }
     if (!isset($entity['_wxuser'])) {
         return array('status' => false, 'info' => "账户信息缺失!");
     }
     $wxuser = $entity['_wxuser'];
     if (!isset($wxuser['wxaccount_id']) || !isset($wxuser['openid'])) {
         return array('status' => false, 'info' => "账户信息缺失!");
     }
     $empty_check = array('nickname', 'avatar', 'province', 'country', 'city');
     foreach ($empty_check as $vo) {
         if (!isset($wxuser[$vo])) {
             $wxuser[$vo] = '';
         }
     }
     addWeixinLog($wxuser, "[测试wxuser 推荐人]设置之前");
     if (!isset($wxuser['referrer'])) {
         $wxuser['referrer'] = 0;
     }
     addWeixinLog($wxuser, "[测试wxuser 推荐人]设置之后");
     if (!isset($wxuser['sex'])) {
         $wxuser['sex'] = 0;
     }
     if (!isset($wxuser['subscribed'])) {
         $wxuser['subscribed'] = 0;
     }
     if (!isset($wxuser['subscribe_time'])) {
         $wxuser['subscribe_time'] = time();
     }
     $username = $entity['username'];
     $password = $entity['password'];
     $email = $entity['email'];
     $mobile = $entity['mobile'];
     $from = $entity['from'];
     $trans = M();
     $trans->startTrans();
     $error = "";
     $flag = false;
     $result = apiCall(UserApi::REGISTER, array($username, $password, $email, $mobile, $from));
     $uid = 0;
     if ($result['status']) {
         $uid = $result['info'];
         $member = array('uid' => $uid, 'realname' => $wxuser['nickname'], 'nickname' => $wxuser['nickname'], 'idnumber' => '', 'sex' => $wxuser['sex'], 'birthday' => time(), 'qq' => '', 'score' => 0, 'login' => 0);
         $result = apiCall(MemberApi::ADD, array($member));
         if (!$result['status']) {
             $flag = true;
             $error = $result['info'];
         }
         if (!$flag) {
             //创建关系表
             $result = apiCall(WxuserFamilyApi::CREATE_ONE_IF_NONE, array($uid, $wxuser['referrer']));
             if (!$result['status']) {
                 $flag = true;
                 $error = $result['info'];
             }
         }
         if (!$flag) {
             $wxuser['uid'] = $uid;
             $wxuser['groupid'] = WxuserGroupModel::DEFAULT_GROUP;
             //
             //继续注册wxuser表
             $result = apiCall(WxuserApi::REGISTER, array($wxuser));
             //                dump($result);
             if (!$result['status']) {
                 $flag = true;
                 $error = $result['info'];
             }
         }
     } else {
         $flag = true;
         $error = $result['info'];
     }
     if ($flag) {
         apiCall(UserApi::DELETE_BY_ID, array($uid));
         $trans->rollback();
         return array('status' => false, 'info' => $error);
     } else {
         $trans->commit();
         return array('status' => true, 'info' => $uid);
     }
 }
Example #18
0
 /**
  * 微信消息接口入口
  * 所有发送到微信的消息都会推送到该操作
  * 所以,微信公众平台后台填写的api地址则为该操作的访问地址
  * 在mp.weixin.qq.com 开发者中心配置的 URL(服务器地址)  http://域名/index.php/home/weixin/index/id/member_public表的id.html
  */
 public function index()
 {
     $this->WX->valid();
     $type = $this->WX->getRev()->getRevType();
     if (C('DEVELOP_MODE')) {
         addWeixinLog($GLOBALS['HTTP_RAW_POST_DATA']);
     }
     //与微信交互的中控服务器逻辑可以自己定义,这里实现一个通用的
     switch ($type) {
         //事件
         case TPWechat::MSGTYPE_EVENT:
             //先处理事件型消息
             $event = $this->WX->getRevEvent();
             switch ($event['event']) {
                 //关注
                 case TPWechat::EVENT_SUBSCRIBE:
                     //二维码关注
                     if (isset($event['eventkey']) && isset($event['ticket'])) {
                     } else {
                         //普通关注
                     }
                     $openid = $this->WX->getRevFrom();
                     $Fans = M('Fans');
                     $fans_info = $Fans->where(array('openid' => $openid))->find();
                     if ($fans_info) {
                         $map = array('openid' => $this->WX->getRevFrom());
                         $Fans->where($map)->setField('subscribe', 1);
                     } else {
                         $wx_info = $this->WX->getUserInfo($this->WX->getRevFrom());
                         $data = array('openid' => $openid, 'username' => $wx_info['nickname'], 'avatar' => $wx_info['headimgurl'], 'subscribe' => 1, 'ctime' => NOW_TIME);
                         $Fans->add($data);
                     }
                     $this->WX->text('你好,欢迎关注宜可姿美胸美体专业机构。并推荐10个好友关注此公众号,即可获得免费乳房专业检测一次,美胸体验项目一次等。地址:平安北大街阿尔卡迪亚小区底商宜可姿美胸美体专业机构,电话:89681919')->reply();
                     break;
                     //扫描二维码
                 //扫描二维码
                 case TPWechat::EVENT_SCAN:
                     break;
                     //地理位置
                 //地理位置
                 case TPWechat::EVENT_LOCATION:
                     break;
                     //自定义菜单 - 点击菜单拉取消息时的事件推送
                 //自定义菜单 - 点击菜单拉取消息时的事件推送
                 case TPWechat::EVENT_MENU_CLICK:
                     switch ($event['key']) {
                         case 'MENU_KEY_NEWS':
                             break;
                         default:
                             # code...
                             break;
                     }
                     break;
                     //自定义菜单 - 点击菜单跳转链接时的事件推送
                 //自定义菜单 - 点击菜单跳转链接时的事件推送
                 case TPWechat::EVENT_MENU_VIEW:
                     $this->WX->text('//自定义菜单 - 点击菜单跳转链接时的事件推送')->reply();
                     break;
                     //自定义菜单 - 扫码推事件的事件推送
                 //自定义菜单 - 扫码推事件的事件推送
                 case TPWechat::EVENT_MENU_SCAN_PUSH:
                     break;
                     //自定义菜单 - 扫码推事件且弹出“消息接收中”提示框的事件推送
                 //自定义菜单 - 扫码推事件且弹出“消息接收中”提示框的事件推送
                 case TPWechat::EVENT_MENU_SCAN_WAITMSG:
                     break;
                     //自定义菜单 - 弹出系统拍照发图的事件推送
                 //自定义菜单 - 弹出系统拍照发图的事件推送
                 case TPWechat::EVENT_MENU_PIC_SYS:
                     break;
                     //自定义菜单 - 弹出拍照或者相册发图的事件推送
                 //自定义菜单 - 弹出拍照或者相册发图的事件推送
                 case TPWechat::EVENT_MENU_PIC_PHOTO:
                     break;
                     //自定义菜单 - 弹出微信相册发图器的事件推送
                 //自定义菜单 - 弹出微信相册发图器的事件推送
                 case TPWechat::EVENT_MENU_PIC_WEIXIN:
                     break;
                     //自定义菜单 - 弹出地理位置选择器的事件推送
                 //自定义菜单 - 弹出地理位置选择器的事件推送
                 case TPWechat::EVENT_MENU_LOCATION:
                     break;
                     //取消关注
                 //取消关注
                 case TPWechat::EVENT_UNSUBSCRIBE:
                     $openid = $this->WX->getRevFrom();
                     $Fans = M('Fans');
                     $fans_info = $Fans->where(array('openid' => $openid))->find();
                     if ($fans_info) {
                         $map = array('openid' => $this->WX->getRevFrom());
                         $Fans->where($map)->setField('subscribe', 0);
                     } else {
                         $wx_info = $this->WX->getUserInfo($this->WX->getRevFrom());
                         $data = array('openid' => $openid, 'username' => $wx_info['nickname'], 'avatar' => $wx_info['headimgurl'], 'subscribe' => 0, 'ctime' => NOW_TIME);
                         $Fans->add($data);
                     }
                     break;
                     //群发接口完成后推送的结果
                 //群发接口完成后推送的结果
                 case TPWechat::EVENT_SEND_MASS:
                     break;
                     //模板消息完成后推送的结果
                 //模板消息完成后推送的结果
                 case TPWechat::EVENT_SEND_TEMPLATE:
                     break;
                 default:
                     break;
             }
             break;
             //文本
         //文本
         case TPWechat::MSGTYPE_TEXT:
             $keyword = trim($this->WX->getRevContent());
             switch ($keyword) {
                 case '1':
                     $this->WX->text('0你好,欢迎关注宜可姿美胸美体专业机构。并推荐10个好友关注此公众号,即可获得免费乳房专业检测一次,美胸体验项目一次等。地址:平安北大街阿尔卡迪亚小区底商宜可姿美胸美体专业机构,电话:89681919')->reply();
                     break;
                 case '2':
                     $data = array(array('Title' => '最新新闻', 'Description' => '测试description1', 'PicUrl' => 'http://shop.zlsgx.com/images/201508/goods_img/3_G_1440030087739.jpg', 'Url' => 'http://wwb.sypole.com/'), array('Title' => '最新新闻', 'Description' => '测试description2', 'PicUrl' => 'http://shop.zlsgx.com/images/201508/goods_img/5_G_1440028482068.jpg', 'Url' => ''), array('Title' => '最新新闻', 'Description' => '测试description3', 'PicUrl' => 'http://shop.zlsgx.com/images/201508/goods_img/5_G_1440028482068.jpg', 'Url' => ''), array('Title' => '最新新闻', 'Description' => '测试description4', 'PicUrl' => 'http://shop.zlsgx.com/images/201508/goods_img/5_G_1440028482068.jpg', 'Url' => ''));
                     $this->WX->news($data)->reply();
                     break;
                 case '投票':
                     $this->WX->text("http://ykzmx.hbjsfx.com/index.php?m=Vote&c=Index&a=index&vid=1")->reply();
                     break;
                 default:
                     $this->WX->text("默认信息...")->reply();
                     break;
             }
             break;
             //图像
         //图像
         case TPWechat::MSGTYPE_IMAGE:
             break;
             //语音
         //语音
         case TPWechat::MSGTYPE_VOICE:
             break;
             //视频
         //视频
         case TPWechat::MSGTYPE_VIDEO:
             break;
             //位置
         //位置
         case TPWechat::MSGTYPE_LOCATION:
             break;
             //链接
         //链接
         case TPWechat::MSGTYPE_LINK:
             break;
         default:
             break;
     }
 }
Example #19
0
 protected function sendOrder($openid, $url, $data)
 {
     $temp = array('touser' => $openid, 'template_id' => 'hIPbD2pnKDr-oUt5LdR3tFlAn2WaFdLi8KTRzSrvgH0', 'url' => C('WEB_SITE_URL') . $url, 'topcolor' => '#FF0000', 'data' => array('first' => array('value' => $data['first'], 'color' => ''), 'keyword1' => array('value' => $data['order_id'], 'color' => ''), 'keyword2' => array('value' => $data['order_status'], 'color' => '#FF0000'), 'keyword3' => array('value' => $data['product_name'], 'color' => ''), 'remark' => array('value' => $data['end_time'], 'color' => '')));
     addWeixinLog(var_export($temp, true));
     $this->WX->sendTemplateMessage($temp);
 }
 /**
  *
  * 设置订单状态
  * TODO:需要记录状态变更日志
  * @param $interval 判断的间隔时间 秒 为单位
  *
  * @return array
  */
 public function orderStatusToCompleted($interval)
 {
     $map['updatetime'] = array('lt', time() - $interval);
     $map['order_status'] = OrdersModel::ORDER_RECEIPT_OF_GOODS;
     $map['comment_status'] = array('NEQ', OrdersModel::ORDER_TOBE_EVALUATE);
     //评价状态不为0
     $result = apiCall(OrdersApi::QUERY_NO_PAGING, array($map));
     foreach ($result['info'] as $order) {
         $codes[] = $order['order_code'];
     }
     addWeixinLog($codes, "ceshi");
     //如果有超过时间的且状态为已收货,佣金发放
     if (count($codes) > 0) {
         apiCall(CommissionCountApi::ADD, array($codes));
     }
     $saveEntity = array('order_status' => OrdersModel::ORDER_COMPLETED);
     $result = $this->model->create($saveEntity, 2);
     if ($result === false) {
         return $this->returnErr($this->model->getError());
     }
     $result = $this->model->where($map)->lock(true)->save();
     //		addWeixinLog($this->model->getLastSql(),"[自动变更订单已收货为已完成SQL]");
     if ($result === FALSE) {
         $error = $this->model->getDbError();
         return $this->returnErr($error);
     } else {
         return $this->returnSuc($result);
     }
 }
 private function getQrcode($id)
 {
     //上传获取一张永久二维码
     $filename = "/qrcode_uid{$id}.jpg";
     if (file_exists(realpath($this->config['downloadFolder']) . $filename)) {
         return $this->config['downloadFolder'] . $filename;
     }
     $json = $this->wxapi->getQrcode($this->config['codeprefix'] . strval($id));
     if ($json['status']) {
         //
         $ticket = $json['msg'];
         if (is_object($json['msg'])) {
             $url = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=" . urlencode($ticket->ticket);
             $this->download_remote_file($url, realpath($this->config['downloadFolder']) . $filename);
             return $this->config['downloadFolder'] . $filename;
         }
     } else {
         addWeixinLog($id, "【获取二维码失败】");
     }
 }
Example #22
0
function post_data($url, $param, $is_file = false, $return_array = true)
{
    if (!$is_file && is_array($param)) {
        $param = JSON($param);
    }
    if ($is_file) {
        $header[] = "content-type: multipart/form-data; charset=UTF-8";
    } else {
        $header[] = "content-type: application/json; charset=UTF-8";
    }
    $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_HTTPHEADER, $header);
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.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, $param);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $res = curl_exec($ch);
    $flat = curl_errno($ch);
    if ($flat) {
        $data = curl_error($ch);
        addWeixinLog($flat, 'post_data flat');
        addWeixinLog($data, 'post_data msg');
    }
    curl_close($ch);
    $return_array && ($res = json_decode($res, true));
    return $res;
}
 private function reply($data, $weixin)
 {
     $key = $data['Content'];
     $keywordArr = array();
     // 插件权限控制
     $token_status = D('Common/AddonStatus')->getList();
     foreach ($token_status as $a => $s) {
         $s == 1 || ($forbit_addon[$a] = $a);
     }
     // 所有安装过的微信插件
     $addon_list = (array) D('Addons')->getWeixinList(false, $token_status);
     /**
      * 通过微信事件来定位处理的插件
      * event可能的值:
      * subscribe : 关注公众号
      * unsubscribe : 取消关注公众号
      * scan : 扫描带参数二维码事件
      * click : 自定义菜单事件
      */
     if ($data['MsgType'] == 'event') {
         $event = strtolower($data['Event']);
         foreach ($addon_list as $vo) {
             require_once ONETHINK_ADDON_PATH . $vo['name'] . '/Model/WeixinAddonModel.class.php';
             $model = D('Addons://' . $vo['name'] . '/WeixinAddon');
             !method_exists($model, $event) || $model->{$event}($data);
         }
         if ($event == 'subscribe') {
             $config = getAddonConfig('Wecome');
             if ($config['type'] == 2) {
                 $key = $data['Content'] = $config['keyword'];
             }
         } else {
             if ($event == 'click' && !empty($data['EventKey'])) {
                 $key = $data['Content'] = $data['EventKey'];
             } else {
                 return true;
             }
         }
     }
     // location : 上报地理位置事件 感谢网友【blue7wings】和【strivi】提供的方案
     if ($data['MsgType'] == 'location') {
         $event = strtolower($data['MsgType']);
         foreach ($addon_list as $vo) {
             require_once ONETHINK_ADDON_PATH . $vo['name'] . '/Model/WeixinAddonModel.class.php';
             $model = D('Addons://' . $vo['name'] . '/WeixinAddon');
             !method_exists($model, $event) || $model->{$event}($data);
         }
     }
     // 通过获取上次缓存的用户状态来定位处理的插件
     $openid = $data['FromUserName'];
     $user_status = S('user_status_' . $openid);
     $accept = $user_status['keywordArr']['accept'];
     if ($accept['type'] == 'regex' && !preg_match($accept['data'], $key) || $accept['type'] == 'array' && !in_array($key, $accept['data'])) {
         $user_status = false;
         S('user_status_' . $openid, null);
         // 可设置规定只能接收某些值,如果用户输入的内容不是规定的值,则放弃当前状态,支持正则和数组两种规定方式
     }
     if (!isset($addons[$key]) && $user_status) {
         $addons[$key] = $user_status['addon'];
         $keywordArr = $user_status['keywordArr'];
         S('user_status_' . $openid, null);
     }
     // 通过插件标识名、插件名或者自定义关键词来定位处理的插件
     if (!isset($addons[$key])) {
         foreach ($addon_list as $k => $vo) {
             $addons[$vo['name']] = $k;
             $addons[$vo['title']] = $k;
             $path = ONETHINK_ADDON_PATH . $vo['name'] . '/keyword.php';
             if (file_exists($path)) {
                 $keywords = (include $path);
                 if (isset($keywords[$key])) {
                     $addons[$key] = $k;
                     $keywordArr = $keywords[$key];
                 }
             }
         }
     }
     // 通过精准关键词来定位处理的插件 token=0是插件安装时初始化的模糊关键词,所有公众号都可以用
     if (!empty($forbit_addon)) {
         $like['addon'] = array('not in', $forbit_addon);
     }
     $like['token'] = array('exp', "='0' or token='{$this->token}'");
     if (!isset($addons[$key])) {
         $like['keyword'] = $key;
         $like['keyword_type'] = 0;
         $keywordArr = M('keyword')->where($like)->order('id desc')->find();
         addWeixinLog(M()->getLastSql(), 'addon1');
         if (!empty($keywordArr['addon'])) {
             $addons[$key] = $keywordArr['addon'];
             $this->request_count($keywordArr);
         }
     }
     // 通过模糊关键词来定位处理的插件
     if (!isset($addons[$key])) {
         unset($like['keyword']);
         $like['keyword_type'] = array('gt', 0);
         $list = M('keyword')->where($like)->order('keyword_length desc, id desc')->select();
         foreach ($list as $keywordInfo) {
             $this->_contain_keyword($keywordInfo, $key, $addons, $keywordArr);
         }
     }
     addWeixinLog(M()->getLastSql(), 'addon2');
     // 通过通配符,查找默认处理方式
     // by 肥仔聪要淡定 2014.6.8
     if (!isset($addons[$key])) {
         unset($like['keyword_type']);
         $like['keyword'] = '*';
         $keywordArr = M('keyword')->where($like)->order('id desc')->find();
         if (!empty($keywordArr['addon'])) {
             $addons[$key] = $keywordArr['addon'];
             $this->request_count($keywordArr);
         }
     }
     addWeixinLog(M()->getLastSql(), 'addon3');
     // 以上都无法定位插件时,如果开启了智能聊天,则默认使用智能聊天插件
     if (!isset($addons[$key]) && isset($addon_list['Chat'])) {
         // 您问我答插件特殊处理
         $YouaskServiceconfig = getAddonConfig('YouaskService');
         // 获取后台插件的配置参数
         if ($YouaskServiceconfig['state'] == 1) {
             $addons[$key] = 'YouaskService';
         } else {
             $addons[$key] = 'Chat';
         }
     }
     // 最终也无法定位到插件,终止操作
     if (!isset($addons[$key]) || !file_exists(ONETHINK_ADDON_PATH . $addons[$key] . '/Model/WeixinAddonModel.class.php')) {
         return false;
     }
     addWeixinLog($addons[$key], 'addon2');
     // 加载相应的插件来处理并反馈信息
     require_once ONETHINK_ADDON_PATH . $addons[$key] . '/Model/WeixinAddonModel.class.php';
     $model = D('Addons://' . $addons[$key] . '/WeixinAddon');
     $model->reply($data, $keywordArr);
     // 运营统计
     tongji($addons[$key]);
 }
Example #24
0
 /**
  * 微信消息接口入口
  * 所有发送到微信的消息都会推送到该操作
  * 所以,微信公众平台后台填写的api地址则为该操作的访问地址
  * 在mp.weixin.qq.com 开发者中心配置的 URL(服务器地址)  http://域名/index.php/home/weixin/index/id/member_public表的id.html
  */
 public function index()
 {
     $this->WX->valid();
     $type = $this->WX->getRev()->getRevType();
     addWeixinLog($GLOBALS['HTTP_RAW_POST_DATA']);
     //与微信交互的中控服务器逻辑可以自己定义,这里实现一个通用的
     switch ($type) {
         //事件
         case TPWechat::MSGTYPE_EVENT:
             //先处理事件型消息
             $event = $this->WX->getRevEvent();
             switch ($event['event']) {
                 //关注
                 case TPWechat::EVENT_SUBSCRIBE:
                     //二维码关注
                     if (isset($event['eventkey']) && isset($event['ticket'])) {
                     } else {
                         //普通关注
                     }
                     $this->WX->text('[呲牙]感谢您关注微拍堂' . PHP_EOL . PHP_EOL . '微拍堂:迅速搭建一个高大上的微拍系统,为您提供完美的拍卖体验' . PHP_EOL . PHP_EOL . '<a href="http://wwb.sypole.com/">点击这里,查看操作步骤</a>')->reply();
                     break;
                     //扫描二维码
                 //扫描二维码
                 case TPWechat::EVENT_SCAN:
                     break;
                     //地理位置
                 //地理位置
                 case TPWechat::EVENT_LOCATION:
                     break;
                     //自定义菜单 - 点击菜单拉取消息时的事件推送
                 //自定义菜单 - 点击菜单拉取消息时的事件推送
                 case TPWechat::EVENT_MENU_CLICK:
                     switch ($event['key']) {
                         case 'MENU_KEY_NEWS':
                             break;
                         default:
                             # code...
                             break;
                     }
                     break;
                     //自定义菜单 - 点击菜单跳转链接时的事件推送
                 //自定义菜单 - 点击菜单跳转链接时的事件推送
                 case TPWechat::EVENT_MENU_VIEW:
                     $this->WX->text('//自定义菜单 - 点击菜单跳转链接时的事件推送')->reply();
                     break;
                     //自定义菜单 - 扫码推事件的事件推送
                 //自定义菜单 - 扫码推事件的事件推送
                 case TPWechat::EVENT_MENU_SCAN_PUSH:
                     break;
                     //自定义菜单 - 扫码推事件且弹出“消息接收中”提示框的事件推送
                 //自定义菜单 - 扫码推事件且弹出“消息接收中”提示框的事件推送
                 case TPWechat::EVENT_MENU_SCAN_WAITMSG:
                     break;
                     //自定义菜单 - 弹出系统拍照发图的事件推送
                 //自定义菜单 - 弹出系统拍照发图的事件推送
                 case TPWechat::EVENT_MENU_PIC_SYS:
                     break;
                     //自定义菜单 - 弹出拍照或者相册发图的事件推送
                 //自定义菜单 - 弹出拍照或者相册发图的事件推送
                 case TPWechat::EVENT_MENU_PIC_PHOTO:
                     break;
                     //自定义菜单 - 弹出微信相册发图器的事件推送
                 //自定义菜单 - 弹出微信相册发图器的事件推送
                 case TPWechat::EVENT_MENU_PIC_WEIXIN:
                     break;
                     //自定义菜单 - 弹出地理位置选择器的事件推送
                 //自定义菜单 - 弹出地理位置选择器的事件推送
                 case TPWechat::EVENT_MENU_LOCATION:
                     break;
                     //取消关注
                 //取消关注
                 case TPWechat::EVENT_UNSUBSCRIBE:
                     break;
                     //群发接口完成后推送的结果
                 //群发接口完成后推送的结果
                 case TPWechat::EVENT_SEND_MASS:
                     break;
                     //模板消息完成后推送的结果
                 //模板消息完成后推送的结果
                 case TPWechat::EVENT_SEND_TEMPLATE:
                     break;
                 default:
                     break;
             }
             break;
             //文本
         //文本
         case TPWechat::MSGTYPE_TEXT:
             addWeixinLog($type);
             $keyword = trim($this->WX->getRevContent());
             switch ($keyword) {
                 case '1':
                     $this->WX->text('[呲牙]感谢您关注微拍堂' . PHP_EOL . PHP_EOL . '微拍堂:迅速搭建一个高大上的微拍系统,为您提供完美的拍卖体验' . PHP_EOL . PHP_EOL . '<a href="http://wwb.sypole.com/">点击这里,查看操作步骤</a>')->reply();
                     break;
                 case '2':
                     $data = array(array('Title' => '最新新闻', 'Description' => '测试description1', 'PicUrl' => 'http://shop.zlsgx.com/images/201508/goods_img/3_G_1440030087739.jpg', 'Url' => 'http://wwb.sypole.com/'), array('Title' => '最新新闻', 'Description' => '测试description2', 'PicUrl' => 'http://shop.zlsgx.com/images/201508/goods_img/5_G_1440028482068.jpg', 'Url' => ''), array('Title' => '最新新闻', 'Description' => '测试description3', 'PicUrl' => 'http://shop.zlsgx.com/images/201508/goods_img/5_G_1440028482068.jpg', 'Url' => ''), array('Title' => '最新新闻', 'Description' => '测试description4', 'PicUrl' => 'http://shop.zlsgx.com/images/201508/goods_img/5_G_1440028482068.jpg', 'Url' => ''));
                     $this->WX->news($data)->reply();
                     break;
                 default:
                     $this->WX->text("默认信息...")->reply();
                     break;
             }
             break;
             //图像
         //图像
         case TPWechat::MSGTYPE_IMAGE:
             break;
             //语音
         //语音
         case TPWechat::MSGTYPE_VOICE:
             break;
             //视频
         //视频
         case TPWechat::MSGTYPE_VIDEO:
             break;
             //位置
         //位置
         case TPWechat::MSGTYPE_LOCATION:
             break;
             //链接
         //链接
         case TPWechat::MSGTYPE_LINK:
             break;
         default:
             break;
     }
 }
 private function sendToWxaccount($wxaccountid, $text)
 {
     $map = array('name' => "WXPAY_OPENID");
     $result = apiCall(ConfigApi::GET_INFO, array($map));
     addWeixinLog($result, "接收订单支付成功的OPENID");
     if ($result['status']) {
         $openidlist = explode(",", $result['info']['value']);
         foreach ($openidlist as $openid) {
             $this->wxapi->sendTextToFans($openid, $text);
         }
     }
 }
 function msgHandler()
 {
     include_once ONETHINK_ADDON_PATH . 'PublicBind/wxBizMsgCrypt.php';
     // 第三方发送消息给公众平台
     $encodingAesKey = 'Wry3C6IG6yzFR55cnje0W7CWd2jqlqQrAIK5ilOIfo3';
     $token = 'youkang120';
     $appId = D('Addons://PublicBind/PublicBind')->component_appid;
     $timeStamp = empty($_GET['timestamp']) ? "" : trim($_GET['timestamp']);
     $nonce = empty($_GET['nonce']) ? "" : trim($_GET['nonce']);
     $msg_sign = empty($_GET['msg_signature']) ? "" : trim($_GET['msg_signature']);
     $encryptMsg = file_get_contents('php://input');
     $pc = new \WXBizMsgCrypt($token, $encodingAesKey, $appId);
     // 第三方收到公众号平台发送的消息
     $msg = '';
     $errCode = $pc->decryptMsg($msg_sign, $timeStamp, $nonce, $encryptMsg, $msg);
     if ($errCode == 0) {
         $data = $this->_xmlToArr($msg);
         error_log("公众号消息:" . $msg);
         $map['name'] = 'PublicBind';
         $config = M('addons')->where($map)->getField('config');
         $config = (array) json_decode($config, true);
         $config['ComponentVerifyTicket'] = $data['ComponentVerifyTicket'];
         $save['config'] = json_encode($config);
         M('addons')->where($map)->save($save);
         echo 'success';
     } else {
         addWeixinLog('解密后失败:' . $errCode, 'setTicket_error');
     }
 }
 /**
  * $bgpath,$arr,$tmppath
  * 背景图,源合成图片,远程文件下载存放临时文件夹
  */
 private function mergeImage($bgpath, $arr, $tmppath, $savefilename)
 {
     $bg = imagecreatefromjpeg($bgpath);
     $bgwidth = imagesx($bg);
     $bgheight = imagesy($bg);
     $bgCopy = imagecreatetruecolor($bgwidth, $bgheight);
     if (function_exists("imagecopyresampled")) {
         imagecopyresampled($bgCopy, $bg, 0, 0, 0, 0, $bgwidth, $bgheight, $bgwidth, $bgheight);
     } else {
         imagecopyresized($bgCopy, $bg, 0, 0, 0, 0, $bgwidth, $bgheight, $bgwidth, $bgheight);
     }
     foreach ($arr as $vo) {
         if ($vo['type'] == 'image') {
             if ($vo['isremote']) {
                 $imgpath = $tmppath . md5($vo['resource']) . ".jpg";
                 if (!file_exists(realpath($imgpath))) {
                     $this->http_get_data($vo['resource'], $imgpath);
                 }
             } else {
                 $imgpath = $vo['resource'];
             }
             $child = imagecreatefromjpeg(realpath($imgpath));
             $pic_width = imagesx($child);
             $pic_height = imagesy($child);
             if (function_exists("imagecopyresampled")) {
                 $new = imagecreatetruecolor($vo['w'], $vo['h']);
                 imagecopyresampled($new, $child, 0, 0, 0, 0, $vo['w'], $vo['h'], $pic_width, $pic_height);
             } else {
                 $new = imagecreate($vo['w'], $vo['h']);
                 imagecopyresized($new, $child, 0, 0, 0, 0, $vo['w'], $vo['h'], $pic_width, $pic_height);
             }
             //合成图片
             imagecopymerge($bgCopy, $new, $vo['x'], $vo['y'], 0, 0, $vo['w'], $vo['h'], 100);
             //			imagejpeg($bgCopy,realpath($savefilename));
             imagedestroy($new);
             imagedestroy($child);
         } elseif ($vo['type'] == 'text') {
             if (isset($vo['color'])) {
                 $color = ImageColorAllocate($bgCopy, $vo['color'][0], $vo['color'][1], $vo['color'][2]);
             } else {
                 $color = ImageColorAllocate($bgCopy, 0, 0, 0);
             }
             //				$name=iconv("gd2312","utf-8","盼盼");
             //				$str = iconv("gb2312","UTF-8",$vo['resource']);
             $str = mb_convert_encoding($vo['resource'], 'utf-8', 'auto');
             imagettftext($bgCopy, $vo['size'], 0, $vo['x'], $vo['y'], $color, $vo['font'], $str);
             //				imagettftext($bgCopy,$vo['size'],0,$vo['x'],$vo['y'],$color,$vo['font'],"adfadsf2312aewrwerwewr");
             //				imagestring($bgCopy,$vo['size'],$vo['x'],$vo['y'],$str,$color);
         }
     }
     imagejpeg($bgCopy, $savefilename);
     imagedestroy($bgCopy);
     addWeixinLog("3。1", "推广二维码");
     return $savefilename;
 }
 public function sendtempmsg($openid, $template_id, $url, $data, $reply, $doctor, $id, $topcolor = '#FF0000', $get)
 {
     $json = $this->get_access_token();
     if ($json['errcode'] == 0) {
         $xml = '{"touser":"******","template_id":"' . $template_id . '","url":"' . $url . '","topcolor":"' . $topcolor . '","data":' . $data . '}';
         echo $xml;
         $res = $this->curlPost($get . $json['access_token'], $xml);
         $res = json_decode($res, true);
         // 记录日志
         if ($res['errcode'] == 0) {
             addWeixinLog($xml, 'post');
         }
         return $res;
     } else {
         return $json;
     }
 }
 private function _replyData($msg, $msgType)
 {
     $msg['ToUserName'] = $this->data['FromUserName'];
     $msg['FromUserName'] = $this->data['ToUserName'];
     $msg['CreateTime'] = NOW_TIME;
     $msg['MsgType'] = $msgType;
     $xml = new \SimpleXMLElement('<xml></xml>');
     $this->_data2xml($xml, $msg);
     $str = $xml->asXML();
     // 记录日志
     addWeixinLog($str, '_replyData');
     echo $str;
 }
 /**
  * 微信消息接口入口
  * 所有发送到微信的消息都会推送到该操作
  * 所以,微信公众平台后台填写的api地址则为该操作的访问地址
  * 在mp.weixin.qq.com 开发者中心配置的 URL(服务器地址)  http://域名/index.php/home/weixin/index/id/member_public表的id.html
  */
 public function index($id = '')
 {
     //
     $this->member_public = M('MemberPublic')->find($id);
     $this->options['appid'] = $this->member_public['appid'];
     //初始化options信息
     $this->options['appsecret'] = $this->member_public['secret'];
     $this->options['encodingaeskey'] = $this->member_public['encodingaeskey'];
     $weObj = new TPWechat($this->options);
     $weObj->valid();
     $weObj->getRev();
     $data = $weObj->getRevData();
     $type = $weObj->getRevType();
     $ToUserName = $weObj->getRevTo();
     $FromUserName = $weObj->getRevFrom();
     $params['weObj'] =& $weObj;
     $params['mp_id'] = $id;
     $params['weOptions'] = $this->options;
     //如果被动响应可获得用户信息就记录下
     if (!empty($id)) {
         //设置当前上下文的公众号id
         $mp_id = get_mpid($id);
     }
     if (!empty($ToUserName)) {
         get_token($ToUserName);
     }
     if (!empty($FromUserName)) {
         $oid = get_openid($FromUserName);
     }
     hook('init_ucuser', $params);
     //把消息分发到addons/ucuser/init_ucuser的方法中,初始化公众号粉丝信息
     $map['openid'] = get_openid();
     $map['mp_id'] = $params['mp_id'];
     $ucuser = D('Ucuser');
     $user = $ucuser->where($map)->find();
     //查询出公众号的粉丝
     $fsub = $user["subscribe"];
     //记录首次关注状态
     //与微信交互的中控服务器逻辑可以自己定义,这里实现一个通用的
     switch ($type) {
         //事件
         case TPWechat::MSGTYPE_EVENT:
             //先处理事件型消息
             $event = $weObj->getRevEvent();
             switch ($event['event']) {
                 //关注
                 case TPWechat::EVENT_SUBSCRIBE:
                     //二维码关注
                     if (isset($event['eventkey']) && isset($event['ticket'])) {
                         //普通关注
                     } else {
                     }
                     if (!$user["subscribe"]) {
                         //未关注,并设置关注状态为已关注
                         $user["subscribe"] = 1;
                         $ucuser->where($map)->save($user);
                     }
                     hook('welcome', $params);
                     //把消息分发到实现了welcome方法的addons中,参数中包含本次用户交互的微信类实例和公众号在系统中id
                     exit;
                     break;
                     //扫描二维码
                 //扫描二维码
                 case TPWechat::EVENT_SCAN:
                     break;
                     //地理位置
                 //地理位置
                 case TPWechat::EVENT_LOCATION:
                     break;
                     //自定义菜单 - 点击菜单拉取消息时的事件推送
                 //自定义菜单 - 点击菜单拉取消息时的事件推送
                 case TPWechat::EVENT_MENU_CLICK:
                     break;
                     //自定义菜单 - 点击菜单跳转链接时的事件推送
                 //自定义菜单 - 点击菜单跳转链接时的事件推送
                 case TPWechat::EVENT_MENU_VIEW:
                     break;
                     //自定义菜单 - 扫码推事件的事件推送
                 //自定义菜单 - 扫码推事件的事件推送
                 case TPWechat::EVENT_MENU_SCAN_PUSH:
                     break;
                     //自定义菜单 - 扫码推事件且弹出“消息接收中”提示框的事件推送
                 //自定义菜单 - 扫码推事件且弹出“消息接收中”提示框的事件推送
                 case TPWechat::EVENT_MENU_SCAN_WAITMSG:
                     break;
                     //自定义菜单 - 弹出系统拍照发图的事件推送
                 //自定义菜单 - 弹出系统拍照发图的事件推送
                 case TPWechat::EVENT_MENU_PIC_SYS:
                     break;
                     //自定义菜单 - 弹出拍照或者相册发图的事件推送
                 //自定义菜单 - 弹出拍照或者相册发图的事件推送
                 case TPWechat::EVENT_MENU_PIC_PHOTO:
                     break;
                     //自定义菜单 - 弹出微信相册发图器的事件推送
                 //自定义菜单 - 弹出微信相册发图器的事件推送
                 case TPWechat::EVENT_MENU_PIC_WEIXIN:
                     break;
                     //自定义菜单 - 弹出地理位置选择器的事件推送
                 //自定义菜单 - 弹出地理位置选择器的事件推送
                 case TPWechat::EVENT_MENU_LOCATION:
                     break;
                     //取消关注
                 //取消关注
                 case TPWechat::EVENT_UNSUBSCRIBE:
                     if ($user["subscribe"]) {
                         $user["subscribe"] = 0;
                         //取消关注设置关注状态为取消
                         $ucuser->where($map)->save($user);
                     }
                     break;
                     //群发接口完成后推送的结果
                 //群发接口完成后推送的结果
                 case TPWechat::EVENT_SEND_MASS:
                     break;
                     //模板消息完成后推送的结果
                 //模板消息完成后推送的结果
                 case TPWechat::EVENT_SEND_TEMPLATE:
                     break;
                 default:
                     break;
             }
             break;
             //文本
         //文本
         case TPWechat::MSGTYPE_TEXT:
             hook('keyword', $params);
             //把消息分发到实现了keyword方法的addons中,参数中包含本次用户交互的微信类实例和公众号在系统中id
             $weObj->reply();
             //在addons中处理完业务逻辑,回复消息给用户
             break;
             //图像
         //图像
         case TPWechat::MSGTYPE_IMAGE:
             break;
             //语音
         //语音
         case TPWechat::MSGTYPE_VOICE:
             break;
             //视频
         //视频
         case TPWechat::MSGTYPE_VIDEO:
             break;
             //位置
         //位置
         case TPWechat::MSGTYPE_LOCATION:
             break;
             //链接
         //链接
         case TPWechat::MSGTYPE_LINK:
             break;
         default:
             break;
     }
     // 记录日志
     if (C('DEVELOP_MODE')) {
         // 是否开发者模式
         addWeixinLog($data, $GLOBALS['HTTP_RAW_POST_DATA']);
     }
 }