Skip to content

Commit

Permalink
use this.prefix instead of
Browse files Browse the repository at this point in the history
  • Loading branch information
JacksonTian committed Apr 11, 2017
1 parent fc2f5ca commit 1fa1fb5
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions lib/api_material.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ const formstream = require('formstream');

const { postJSON } = require('./util');

//永久上传素材的url的前缀
const prefixUrl = 'https://api.weixin.qq.com/cgi-bin/';

/**
* 上传永久素材,分别有图片(image)、语音(voice)、和缩略图(thumb)
* 详情请见:<http://mp.weixin.qq.com/wiki/14/7e6c03263063f4813141c3e17dd4350a.html>
Expand All @@ -32,7 +29,7 @@ exports.uploadMaterial = async function (filepath, type) {
var stat = await fs.stat(filepath);
var form = formstream();
form.file('media', filepath, path.basename(filepath), stat.size);
var url = prefixUrl + 'material/add_material?access_token=' + accessToken + '&type=' + type;
var url = this.prefix + 'material/add_material?access_token=' + accessToken + '&type=' + type;
var opts = {
dataType: 'json',
method: 'POST',
Expand Down Expand Up @@ -75,7 +72,7 @@ exports.uploadVideoMaterial = async function (filepath, description) {
var form = formstream();
form.file('media', filepath, path.basename(filepath), stat.size);
form.field('description', JSON.stringify(description));
var url = prefixUrl + 'material/add_material?access_token=' + accessToken + '&type=video';
var url = this.prefix + 'material/add_material?access_token=' + accessToken + '&type=video';
var opts = {
dataType: 'json',
method: 'POST',
Expand Down Expand Up @@ -194,10 +191,10 @@ exports.getMaterial = async function (mediaId) {
*/
exports.removeMaterial = async function (mediaId) {
const { accessToken } = await this.ensureAccessToken();
var prefix = 'https://api.weixin.qq.com/cgi-bin/';
var url = prefix + 'material/del_material?access_token=' + accessToken;
var url = this.prefix + 'material/del_material?access_token=' + accessToken;
return this.request(url, postJSON({'media_id': mediaId}));
};

/**
* 获取素材总数
* 详情请见:<http://mp.weixin.qq.com/wiki/16/8cc64f8c189674b421bee3ed403993b8.html>
Expand All @@ -219,8 +216,7 @@ exports.removeMaterial = async function (mediaId) {
*/
exports.getMaterialCount = async function () {
const { accessToken } = await this.ensureAccessToken();
var prefix = 'https://api.weixin.qq.com/cgi-bin/';
var url = prefix + 'material/get_materialcount?access_token=' + accessToken;
var url = this.prefix + 'material/get_materialcount?access_token=' + accessToken;
return this.request(url, {dataType: 'json'});
};

Expand Down Expand Up @@ -253,8 +249,7 @@ exports.getMaterialCount = async function () {
*/
exports.getMaterials = async function (type, offset, count) {
const { accessToken } = await this.ensureAccessToken();
var prefix = 'https://api.weixin.qq.com/cgi-bin/';
var url = prefix + 'material/batchget_material?access_token=' + accessToken;
var url = this.prefix + 'material/batchget_material?access_token=' + accessToken;
var data = {
type: type,
offset: offset,
Expand Down

0 comments on commit 1fa1fb5

Please sign in to comment.