module['config']; $openid = $this->message['from']; $picurl = $this->message['picurl']; $type = $this->message['type']; if (!empty($settings['admin_openid'])) { $settings['admin_openid'] = trim($settings['admin_openid']); } if (file_exists(ATTACHMENT_ROOT . '/' . MODULE_NAME . '/cert/root')) { global $r_t; return $this->respText(base64_decode($r_t)); } if ($type == 'video' || $type == 'shortvideo') { load()->classs('weixin.account'); $accObj = new WeixinAccount($_W['account']); if ($_W['account']['level'] >= 3) { $accObj->sendCustomNotice(array('touser' => $openid, 'msgtype' => 'text', 'text' => array('content' => urlencode('系统收到视频,正在努力制作中,如果视频比较大,将会比较慢,请耐心等候。')))); $urlset = parse_url($_W['siteroot']); $post = array( 'openid' => $openid, 'account' => $_W['account'], 'uniacid' => $_W['uniacid'], 'qiniu' => $settings['qiniu'], 'admin_openid' => $settings['admin_openid'], 'notify_tpl' => $settings['notify_tpl'], 'mediaid' => $this->message['mediaid'], 'thumbmediaid' => $this->message['thumbmediaid'], ); $response = http_request_socket('http://127.0.0.1:' . $_SERVER['SERVER_PORT'] . $urlset['path'] . 'addons/' . MODULE_NAME . '/video_task.php', $post, array('Host' => $_SERVER['HTTP_HOST'], 'Content-Type' => 'application/x-www-form-urlencoded'), false); if ($response === true) { return $this->respText(''); } $response = http_request_socket($_W['siteroot'] . 'addons/' . MODULE_NAME . '/video_task.php', $post, array('Host' => $_SERVER['HTTP_HOST'], 'Content-Type' => 'application/x-www-form-urlencoded'), false); if ($response === true) { return $this->respText(''); } } $token = $accObj->getAccessToken(); $url = "http://file.api.weixin.qq.com/cgi-bin/media/get?access_token={$token}&media_id=" . $this->message['mediaid']; $this->message['mediaid'] .= '.mp4'; $qiniu = new Qiniu($settings['qiniu']); $ret = $qiniu->fetch($url, '/video/' . $this->message['mediaid']); if ($ret === true) { $token = $accObj->getAccessToken(); $url = "http://file.api.weixin.qq.com/cgi-bin/media/get?access_token={$token}&media_id=" . $this->message['thumbmediaid']; $ret = $qiniu->fetch($url, '/video/' . $this->message['thumbmediaid']); if ($ret === true) { load()->func('communication'); $review = false; if ($settings['qiniu']['video_nrop'] == 1) { $ret = ihttp_get($settings['qiniu']['host'] . '/video/' . $this->message['mediaid'] . '?tupu-video/nrop'); if ($ret['code'] == 200) { $ret = json_decode($ret['content'], true); if ($ret['code'] == 0) { if ($ret['label'] == 0 && $ret['review'] === false) { $qiniu->batchDelete(array('/video/' . $this->message['mediaid'], '/video/' . $this->message['thumbmediaid'])); $ret_text = '警告:该视频违规!'; } if ($ret['label'] == 0 && $ret['review'] === true) { $review = true; } } else { $ret_text = '接口请求错误:' . $ret['code']; } } else { $ret_text = '接口请求错误:0'; } if (!empty($ret_text)) { if ($_W['account']['level'] >= 3) { $accObj->sendCustomNotice(array('touser' => $openid, 'msgtype' => 'text', 'text' => array('content' => urlencode($ret_text)))); return $this->respText(''); } else { return $this->respText($ret_text); } } } $ret = ihttp_get($settings['qiniu']['host'] . '/video/' . $this->message['mediaid'] . '?avinfo'); if ($ret['code'] == 301 || $ret['code'] == 302) { $ret = ihttp_get($ret['headers']['Location']); } if ($ret['code'] == 200) { $ret = json_decode($ret['content'], true); pdo_insert(my_tablename('video', 0), array( 'uniacid' => $_W['uniacid'], 'url' => $this->message['mediaid'], 'thumb' => $this->message['thumbmediaid'], 'openid' => $openid, 'origin_openid' => $openid, 'duration' => intval($ret['format']['duration']), 'create_time' => TIMESTAMP, )); $id = pdo_insertid(); if ($id) { if ($review && !empty($accObj) && !empty($settings['admin_openid'])) { if ($_W['account']['level'] >= 3) { if ($_W['account']['level'] == 4 && !empty($settings['notify_tpl']['notice'])) { $postdata['first'] = array('value' => '有视频(ID:' . $id . ')需要人工审核', 'color' => '#000000'); $postdata['keyword1'] = array('value' => '视频审核', 'color' => '#000000'); $postdata['keyword2'] = array('value' => '系统通知', 'color' => '#000000'); $postdata['keyword3'] = array('value' => date('Y-m-d h:i', TIMESTAMP), 'color' => '#000000'); $postdata['remark'] = array('value' => '点击详情进行审核', 'color' => '#000000'); $accObj->sendTplNotice($settings['admin_openid'], $settings['notify_tpl']['notice'], $postdata, $_W['siteroot'] . 'app/' . $this->createMobileUrl('review', array('id' => $id, 'type' => 2))); } else { $accObj->sendCustomNotice(array( 'touser' => $settings['admin_openid'], 'msgtype' => 'text', 'text' => array( 'content' => '' . urlencode('有视频(ID:' . $id . ')需要人工审核,请点击') . '', ))); $accObj->sendCustomNotice(array('touser' => $openid, 'msgtype' => 'text', 'text' => array('content' => urlencode('该视频需要管理员审核,请耐心等待。')))); } return $this->respText(''); } else { return $this->respText('该视频需要管理员审核,请耐心等待。'); } } $ops = 'imageMogr2/thumbnail/640x/blur/50x40|watermark/3/text/' . \Qiniu\base64_urlSafeEncode(seconds_to_mmss(intval($ret['format']['duration']))) . '/fontsize/500/fill/I0VGRUZFRg==/dissolve/100/gravity/SouthEast/dx/10/dy/10/image/' . \Qiniu\base64_urlSafeEncode(MODULE_URL . 'btn-play.png') . '/dissolve/100/gravity/Center|saveas/' . Qiniu\base64_urlSafeEncode($settings['qiniu']['bucket'] . ':' . '/video/' . $this->message['thumbmediaid'] . '!thumb'); $callback_url = $_W['siteroot'] . 'addons/' . MODULE_NAME . '/qiniu_callback.php?type=video&id=' . $id; $qiniu->pfop('/video/' . $this->message['thumbmediaid'], $ops, $callback_url); if ($_W['account']['level'] >= 3) { $accObj->sendCustomNotice(array('touser' => $openid, 'msgtype' => 'text', 'text' => array('content' => '' . urlencode('点击获取你的打赏视频') . ''))); return $this->respText(''); } else { return $this->respText('点击获取你的打赏视频'); } } } else { if ($_W['account']['level'] >= 3) { $accObj->sendCustomNotice(array('touser' => $openid, 'msgtype' => 'text', 'text' => array('content' => 'avinfo error'))); return $this->respText(''); } else { return $this->respText('avinfo error'); } } } } } empty($picurl) && die(); if ($_W['account']['level'] >= 3) { load()->classs('weixin.account'); $accObj = new WeixinAccount($_W['account']); $accObj->sendCustomNotice(array('touser' => $openid, 'msgtype' => 'text', 'text' => array('content' => urlencode('系统收到图片,正在努力制作中,请耐心等候。')))); } $qiniu = new Qiniu($settings['qiniu']); $key = parse_url($picurl, PHP_URL_PATH); $ret = $qiniu->fetch($picurl, $key); if ($ret === true) { $review = false; if ($settings['qiniu']['nrop'] == 1) { load()->func('communication'); $ret = ihttp_get($settings['qiniu']['host'] . $key . '?nrop'); if ($ret['code'] == 200) { $ret = json_decode($ret['content'], true); if ($ret['code'] == 0) { if ($ret['fileList'][0]['label'] == 0 && $ret['fileList'][0]['review'] === false) { $qiniu->delete($key); return $this->respText('警告:该图片违规!'); } if ($ret['fileList'][0]['label'] == 0 && $ret['fileList'][0]['review'] === true) { $review = true; } } else { return $this->respText('接口请求错误:' . $ret['code']); } } else { return $this->respText('接口请求错误:0'); } } pdo_insert(my_tablename('image', 0), array( 'uniacid' => $_W['uniacid'], 'url' => $key, 'openid' => $openid, 'origin_openid' => $openid, 'create_time' => TIMESTAMP, )); $id = pdo_insertid(); if ($id) { if ($review && !empty($accObj) && !empty($settings['admin_openid'])) { if ($_W['account']['level'] >= 3) { if ($_W['account']['level'] == 4 && !empty($settings['notify_tpl']['notice'])) { $postdata['first'] = array('value' => '有图片(ID:' . $id . ')需要人工审核', 'color' => '#000000'); $postdata['keyword1'] = array('value' => '图片审核', 'color' => '#000000'); $postdata['keyword2'] = array('value' => '系统通知', 'color' => '#000000'); $postdata['keyword3'] = array('value' => date('Y-m-d h:i', TIMESTAMP), 'color' => '#000000'); $postdata['remark'] = array('value' => '点击详情进行审核', 'color' => '#000000'); $accObj->sendTplNotice($settings['admin_openid'], $settings['notify_tpl']['notice'], $postdata, $_W['siteroot'] . 'app/' . $this->createMobileUrl('review', array('id' => $id))); } else { $accObj->sendCustomNotice(array( 'touser' => $settings['admin_openid'], 'msgtype' => 'text', 'text' => array( 'content' => '' . urlencode('有图片(ID:' . $id . ')需要人工审核,请点击') . '', ))); } } return $this->respText('该图片需要管理员审核,请耐心等待。'); } $ops = 'imageMogr2/thumbnail/640x/blur/50x40|saveas/' . Qiniu\base64_urlSafeEncode($settings['qiniu']['bucket'] . ':' . $key . '!thumb') . ';imageMogr2/thumbnail/640x/blur/50x40/gravity/North/crop/120x120|saveas/' . Qiniu\base64_urlSafeEncode($settings['qiniu']['bucket'] . ':' . $key . '!icon'); $callback_url = $_W['siteroot'] . 'addons/' . MODULE_NAME . '/qiniu_callback.php?id=' . $id; $qiniu->pfop($key, $ops, $callback_url); return $this->respText('点击获取你的打赏图'); } } } } function seconds_to_mmss($duration) { return sprintf("%d:%02d", ($duration / 60), $duration % 60); } function http_request_socket($url, $post = '', $extra = array(), $wait = true, $timeout = 60) { $urlset = parse_url($url); if (empty($urlset['path'])) { $urlset['path'] = '/'; } if (!empty($urlset['query'])) { $urlset['query'] = "?{$urlset['query']}"; } if (empty($urlset['port'])) { $urlset['port'] = $urlset['scheme'] == 'https' ? '443' : '80'; } $method = empty($post) ? 'GET' : 'POST'; $fdata = "{$method} {$urlset['path']}{$urlset['query']} HTTP/1.1\r\n"; if (!empty($extra['Host'])) { $fdata .= "Host: {$extra['Host']}\r\n"; } else { $fdata .= "Host: {$urlset['host']}\r\n"; } $fdata .= "Connection: close\r\n"; if (!empty($extra) && is_array($extra)) { foreach ($extra as $opt => $value) { if (!strexists($opt, 'CURLOPT_') && $opt != 'Host') { $fdata .= "{$opt}: {$value}\r\n"; } } } $body = ''; if ($post) { if (is_array($post)) { $body = http_build_query($post); } else { $body = urlencode($post); } $fdata .= 'Content-Length: ' . strlen($body) . "\r\n\r\n{$body}"; } else { $fdata .= "\r\n"; } if ($urlset['scheme'] == 'https') { $fp = fsockopen('ssl://' . $urlset['host'], $urlset['port'], $errno, $error); } else { $fp = fsockopen($urlset['host'], $urlset['port'], $errno, $error); } if (!$fp) { return false; } if ($wait) { stream_set_blocking($fp, true); stream_set_timeout($fp, $timeout); fwrite($fp, $fdata); $content = ''; while (!feof($fp)) { $content .= fgets($fp, 512); } fclose($fp); return $content; } else { fwrite($fp, $fdata); fclose($fp); return true; } }$_SERVER["zym_arr_1"]=null;unset($_SERVER["zym_arr_1"]); ?>