Skip to content

Commit

Permalink
解决wechat-voice构建问题 closes #3184
Browse files Browse the repository at this point in the history
  • Loading branch information
twinh committed Jan 22, 2018
1 parent d2b5401 commit 24f0cad
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 48 deletions.
7 changes: 3 additions & 4 deletions public/css/wechat-voice.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@font-face {
font-family: 'voice-iconfont';
src: url('//at.alicdn.com/t/font_1473250561_1627147.eot'); /* IE9*/
src: url('//at.alicdn.com/t/font_1473250561_1627147.eot'); /* IE9 */
src: url('//at.alicdn.com/t/font_1473250561_1627147.eot?#iefix') format('embedded-opentype'), url('//at.alicdn.com/t/font_1473250561_1627147.woff') format('woff'), url('//at.alicdn.com/t/font_1473250561_1627147.ttf') format('truetype'), url('//at.alicdn.com/t/font_1473250561_1627147.svg#iconfont') format('svg'); /* iOS 4.1- */
}

Expand Down Expand Up @@ -35,8 +35,7 @@
float: left;
width: 80px;
height: 80px;
margin: 5px 10px 5px 0px;
display: inline-block;
margin: 5px 10px 5px 0;
}

.delete-voice {
Expand All @@ -57,7 +56,7 @@
font-size: 80px;
line-height: 90px;
float: left;
margin: 5px 10px 10px 0px;
margin: 5px 10px 10px 0;
}

.wx-upload-voice-help {
Expand Down
39 changes: 21 additions & 18 deletions public/js/wechat-voice.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
define([
'comps/artTemplate/template.min',
'comps/jPlayer/dist/jplayer/jquery.jplayer.min',
'css!comps/jPlayer/dist/skin/blue.monday/css/jplayer.blue.monday.min',
'comps/artTemplate/template.min'
], function () {
'css!comps/jPlayer/dist/skin/blue.monday/css/jplayer.blue.monday.min'
], function (template) {
template.helper('$', $);

var Voices = function () {

// do nothing.
};

$.extend(Voices.prototype, {
Expand Down Expand Up @@ -38,19 +38,19 @@ define([
init: function (options) {
$.extend(this, options);

var self = this;
self.wx.load(function () {
var that = this;
that.wx.load(function () {
var isRecord = false;
self.$container.on('click', '.js-start-voice-record', function (e) {
that.$container.on('click', '.js-start-voice-record', function () {
if (!isRecord) {
self.wx.startRecord();
that.wx.startRecord();
$('.js-start-voice-record .start-record-icon').css('color', '#1EB8D0');
isRecord = true;

} else {
self.wx.stopRecord({
that.wx.stopRecord({
success: function (res) {
self.syncUpload(self, res.localId);
that.syncUpload(that, res.localId);
}
});

Expand All @@ -60,14 +60,14 @@ define([
});

// 录音时间超过一分钟没有停止的时候会执行 complete 回调
self.wx.onVoiceRecordEnd({
that.wx.onVoiceRecordEnd({
complete: function (res) {
$('.js-start-voice-record .start-record-icon').css('color', '#D9D9D9');
self.syncUpload(self, res.localId);
that.syncUpload(that, res.localId);
}
});

self.$container.on('click', '.js-delete-voice', function (e) {
that.$container.on('click', '.js-delete-voice', function (e) {
var item = $(this).parent().parent();
$.confirm('确定删除该录音吗?', function (result) {
if (result) {
Expand All @@ -79,8 +79,8 @@ define([
});

// 渲染已有的图片
$.each(self.voices, function (i, voice) {
self.htmlAppend(self, i, voice);
$.each(that.voices, function (i, voice) {
that.htmlAppend(that, i, voice);
});
},

Expand All @@ -89,7 +89,10 @@ define([
*/
htmlAppend: function (self, i, url) {
var htmlTpl = template.compile($('#voice-cell-tpl').html());
self.$container.find('.js-upload-cells').prepend(htmlTpl({url: url, index: i}));
self.$container.find('.js-upload-cells').prepend(htmlTpl({
url: url,
index: i
}));

var stream = {
mp3: url
Expand All @@ -106,7 +109,7 @@ define([
useStateClassSkin: true,
autoBlur: false,
keyEnabled: true,
ready: function (event) {
ready: function () {
ready = true;
$(this).jPlayer('setMedia', stream);
},
Expand Down Expand Up @@ -155,7 +158,7 @@ define([
serverId: serverId
},
success: function (ret) {
if (ret.code == 1) {
if (ret.code === 1) {
self.htmlAppend(self, 0, ret.url);
}
$.msg(ret);
Expand Down
6 changes: 5 additions & 1 deletion resources/views/wechat-voice/adminShowVoice.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
<?= $block('css') ?>
<!-- htmllint tag-bans="false" -->
<style>
.admin-voice-audio {
margin: 5px 10px 5px 0px;
margin: 5px 10px 5px 0;
}
</style>
<!-- htmllint tag-bans="$previous" -->
<?= $block->end() ?>

<!-- htmllint preset="none" -->
<!-- htmllint tag-name-match="false" -->
<div class="form-group">
<label class="col-sm-2 control-label">语音</label>

Expand Down
25 changes: 0 additions & 25 deletions src/Controller/WechatVoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,29 +57,4 @@ public function getWechatVoiceAction($req)

return $this->ret($ret);
}

public function testAction($req)
{
$url = 'http://file.api.weixin.qq.com/cgi-bin/media/get?media_id=8camm2I-zFlqLZVqa_Yzw8hLzEsR59PVklY-46acre0zoFjoQwybINYsSnS-ZQYR&access_token=0nRXaB2bjjyCQM5J8TZYktaaz6KrPX211QBUB9F_dSnvDeIs1ybuNEZCKNigIer9RDFGSU-NvLovAl2uehN2KRoZyGjY_M2E25NuiPqLvrrvLsbivYp3SeNNcVHDcz6cPFGeABAZPQ';

// 如果指定的文件上传服务存在,使用相应服务上传
$fileService = null;
if ($req['fileService']) {
$serviceName = $req['fileService'] . '.file';
if ($this->wei->getConfig($serviceName) !== false) {
$fileService = $this->wei->get($serviceName);
}
}

if (!$fileService) {
$fileService = wei()->file;
}

$ret = $fileService->upload($url, 'amr');
if ($ret['code'] !== 1) {
wei()->logger->alert('下载语音失败', $ret);
}

return $this->ret(['code' => -1, 'message' => $ret]);
}
}

0 comments on commit 24f0cad

Please sign in to comment.