function edit($ctx) { _render('form'); try { $channel_id = (string) $_GET['id'] !== '' ? intval($_GET['id']) : ''; $m = Channel::get($channel_id); if (!$m) { _redirect($this->_list_url()); return; } $wx_info = WxChannelInfo::get($channel_id); if ($_POST) { $f = $_POST['f']; // 生成二维码 每次保存都更新一次 但是如果已经发放了 其实不能更新的 因为会过期 所以,永久的不能更新 临时的更新可以处理 $expire_type = intval($f['expire_type']); $expire_seconds = intval($f['expire_seconds']); $expire_seconds = max(0, $expire_seconds); $status = intval($f['status']); $wx_info = WxChannelInfo::qrcode_create($channel_id, $expire_type, $expire_seconds, $status); _redirect($this->_list_url()); } $ctx->wx_info = $wx_info; $ctx->m = $m; } catch (Exception $e) { $msg = $e->getMessage(); $ctx->errmsg = $msg; $ctx->m = $m; $ctx->wx_info = $wx_info; } }
function reply_channel_subscribe($xml) { $from = $xml->FromUserName; $to = $xml->ToUserName; $type = $xml->MsgType; $event = strtolower($xml->Event); $event_key = $xml->EventKey; $ticket = $xml->Ticket; $in_event = array(WxReplyKeyword::EVENT_TYPE_SCAN, WxReplyKeyword::EVENT_TYPE_SUBSCRIBE); if ($type == WxReplyKeyword::KEYWORD_TYPE_EVENT && in_array($event, $in_event)) { $channel_info = WxReplyKeyword::check_wechat_subscribe_scene_id($event_key); if (!$channel_info) { return false; } $channel_id = $channel_info->id; $wx_channel_info = WxChannelInfo::get($channel_id); if (!$wx_channel_info || $wx_channel_info->status != WxChannelInfo::STATUS_YES || $wx_channel_info->qrcode_ticket != $ticket) { return false; } $keyword = WxReplyKeyword::CHANNEL_SUBSCRIBE_PREFIE . $channel_id; $where = "type = '{$type}' and keyword = '{$keyword}'"; $kw = WxReplyKeyword::findOne($where, 'id desc'); if ($kw) { $item = WxReplyItem::get($kw->item_id); if ($item) { $wrap = $item->type == 'news' ? true : false; $str = $item->content; $reply_list = @json_decode($str, true); if ($reply_list) { $this->send_reply_list($to, $from, $reply_list, $wrap); } Logger::info("扫描渠道关注二维码, 粉丝关注事件, 自动回复成功, 微信openid : {$from} ,服务号微信id {$to} 渠道ID {$channel_info->id}"); return true; } } } return false; }