微信项目,调用相册相机,上传图像Angularjs Service
来源:互联网 发布:淘宝售后评价在哪里写 编辑:程序博客网 时间:2024/04/29 04:31
app.service("wxService", function($http, http, $timeout, errorMsg) {
// 调用相机
this.chooseImage = function(url, success){
init(url);
wx.ready(function(){
wx.chooseImage({
count: 1, // 默认9
sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
success: function (res) {
var localIds = res.localIds; // 返回选定照片的本地ID列表,localId可以作为img标签的src属性显示图片
$timeout(function(){
for(var i = 0; i < localIds.length; i++){
wx.uploadImage({
localId: localIds[i],// 需要上传的图片的本地ID,由chooseImage接口获得
isShowProgressTips: 1, // 默认为1,显示进度提示
success: function (res) {
var serverId = res.serverId; // 返回图片的服务器端ID
$http.get(http + "/customer/portrait?fileId=" + serverId).success(function(resp){
if(resp.codeText == "OK") {
layer.msg("上传成功");
success(resp.data);
}else{
layer.msg("上传失败");
}
}).error(function(resp) {
layer.msg(errorMsg);
});
}
});
}
}, 0);
}
});
});
}
// 初始化
function init(url){
var index = url.indexOf("#");
if(index > -1){
url = url.substring(0, index);
}
$http.get(http + "/customer/signature?currentUrl=" + url).success(function(resp) {
if(resp.codeText == "OK"){
wx.config({
debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
appId: resp.data.appId, // 必填,公众号的唯一标识
timestamp: resp.data.timestamp, // 必填,生成签名的时间戳
nonceStr: resp.data.noncestr, // 必填,生成签名的随机串
signature: resp.data.signature,// 必填,签名
jsApiList: ['chooseImage','uploadImage'] // 必填,需要使用的JS接口列表
});
wx.error(function(res){
console.log("wx.error");
});
}
});
}
//初始化
window.onerror = function(msg, url, line) {
var idx = url.lastIndexOf("/");
if (idx > -1) {
url = url.substring(idx + 1);
}
alert("ERROR in " + url + " (line #" + line + "): " + msg);
return false;
};
});
// 调用相机
this.chooseImage = function(url, success){
init(url);
wx.ready(function(){
wx.chooseImage({
count: 1, // 默认9
sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
success: function (res) {
var localIds = res.localIds; // 返回选定照片的本地ID列表,localId可以作为img标签的src属性显示图片
$timeout(function(){
for(var i = 0; i < localIds.length; i++){
wx.uploadImage({
localId: localIds[i],// 需要上传的图片的本地ID,由chooseImage接口获得
isShowProgressTips: 1, // 默认为1,显示进度提示
success: function (res) {
var serverId = res.serverId; // 返回图片的服务器端ID
$http.get(http + "/customer/portrait?fileId=" + serverId).success(function(resp){
if(resp.codeText == "OK") {
layer.msg("上传成功");
success(resp.data);
}else{
layer.msg("上传失败");
}
}).error(function(resp) {
layer.msg(errorMsg);
});
}
});
}
}, 0);
}
});
});
}
// 初始化
function init(url){
var index = url.indexOf("#");
if(index > -1){
url = url.substring(0, index);
}
$http.get(http + "/customer/signature?currentUrl=" + url).success(function(resp) {
if(resp.codeText == "OK"){
wx.config({
debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
appId: resp.data.appId, // 必填,公众号的唯一标识
timestamp: resp.data.timestamp, // 必填,生成签名的时间戳
nonceStr: resp.data.noncestr, // 必填,生成签名的随机串
signature: resp.data.signature,// 必填,签名
jsApiList: ['chooseImage','uploadImage'] // 必填,需要使用的JS接口列表
});
wx.error(function(res){
console.log("wx.error");
});
}
});
}
//初始化
window.onerror = function(msg, url, line) {
var idx = url.lastIndexOf("/");
if (idx > -1) {
url = url.substring(idx + 1);
}
alert("ERROR in " + url + " (line #" + line + "): " + msg);
return false;
};
});
0 0
- 微信项目,调用相册相机,上传图像Angularjs Service
- iOS调用相册、相机、上传
- 调取微信相册相机
- android 调用相机 相册 及图片上传
- ios调用相册或相机上传图片
- iOS调用相册、相机、上传等问题
- iOS调用相册、相机、上传等问题
- iOS 相册 相机的调用及上传
- iOS调用相机,相册,上传头像
- 调用系统相机相册上传头像
- Android调用系统相机,相册,并设置为圆形图像
- Android调用手机相机和相册拿到图片保存上传
- android开发之上传图片和调用相机以及相册
- iOS - 调用相机相册的方法 + 上传图片
- iOS调用系统相册,相机上传头像的基本技巧
- 调用系统相机拍照,从相册选取图片上传
- iOS学习:调用相机和相册,选择图片上传
- Android头像上传(本地相册和调用系统相机)
- 使用Java的设备列表(很全面)
- 面向对象之反射
- Jsp Problem与解决
- asp.net mvc Code First模式下迁移更新数据库
- Javascript 严格模式详解
- 微信项目,调用相册相机,上传图像Angularjs Service
- SVG图案和渐变填充
- mysql安装详情
- Java加密技术(四)——非对称加密算法RSA
- 开机提示grub可咋办啊
- 3 sum
- Android中滑动ListView的黑色背景和点击ListView某个item的橙黄色背景怎么去掉
- 内存管理-sbrk()/brk()、mmap()/munmap()
- C++笔记 - 函数传参数学习