New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

wechat-media

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wechat-media

manage wechat-enterprise media

latest
npmnpm
Version
1.0.4
Version published
Maintainers
1
Created
Source

注意: 该npm包需要依赖node后台模板中的 ../libs/utils.js 和 ../config.dev/serverConfig.json

Download resource

var Wechat_media = require('wechat_media');
var company_id = "561f72fbe419be013b8b4zyx";
var option = {
	url: media_url,					//需要下载的资源url
	name: filename,					//要存储在本地的文件名
	type: media_type,				//文件类型,可以是"voice"或"image"
	savePath: savePath				//文件存储的相对路径
	};

Wechat_media.download(company_id, option).then(function(ret){
	if(ret.result){
		var save_url = ret.data.media_url; 			//下载后的媒体文件可以访问的url地址,你必须首先在serverConfig中设置 static_url,这个将会是 static_url+option.name
		var	type = ret.data.type;					//type为"voice"或"image"
		var file = ret.data.file;					//本地存储的文件地址
	}else{
		throw new Error("下载文件时出错");
	}
}).catch(function(e){
	console.log(e||e.stack);
})

Upload resource to Wechat

var Wechat_media = require('wechat_media');
var company_id = "561f72fbe419be013b8b4zyx";
var option = {
	media_url: media_url,		//非必须参数,由download方法返回
	file: filepath,				//本地存储文件的地址
	type: media_type			//可以是"type"或"image"
	};
Wechat_media.upload(company_id, option).then(function(ret){
	if(ret.result){
		var media_id = ret.data.media_id,			//上传到微信后返回的media_id
	}else{
		throw new Error("上传文件时出错");
		}
	}).catch(function(e){
		console.log(e||e.stack);
	})

Save resource from Wechat

var Wechat_media = require('wechat_media');
var company_id = "561f72fbe419be013b8b4zyx";
var option = {
	media_id: media_id,				//要从微信获取的素材的media_id
	name: filename,					//要存储在本地的文件名
	type: media_type,				//文件类型,可以是"voice"或"image"
	savePath: savePath				//文件存储的相对路径
};

Wechat_media.saveMedia(company_id, option).then(function(ret){
	if(ret.result){
		var media_url = ret.data.media_url;			//下载后的媒体文件可以访问的url地址,你必须首先在serverConfig中设置 static_url,这个将会是 static_url+option.name
		var	type = ret.data.type;					//type为"voice"或"image"
		var file = ret.data.file;					//本地存储的文件地址
	}else{
		throw new Error("下载文件时出错");
		}
}).catch(function(e){
	console.log(e||e.stack);
})

Installation

$ npm install wechat-media

Keywords

wechat

FAQs

Package last updated on 10 Nov 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts