zoukankan      html  css  js  c++  java
  • 微信发起摄像头接口请求 上传头像 图片

    var requestSign = require('../../../../utils/requestData.js');
    var api = require('../../../../utils/api.js').open_api;
    var util = require('../../../../utils/util.js');
    var header = getApp().header;
    var time = require('../../../../utils/time.js');
    const app = getApp();

    小程序发起头像请求 可以选择头像上传 或者 拍照 调用摄像头接口
    // 微信头像上传

        <view class="wxcode-imgbox">
            <image src="{{tempFile1?tempFile1:'../../../imgs/zhifubaocode.png'}}" bindtap="zfbTakePhoto" style="vertical-align: middle;430rpx; height: 430rpx;"></image>
            <image src="../../../imgs/del.png" bindtap="delZfbPhoto" style="vertical-align: middle;44rpx; height: 44rpx;position: absolute;right:174rpx;top:12rpx;z-index:9"></image>
        </view>
      wxTakePhoto: function () {
        // console.log("wx微信头像上传")
        const that = this;
        wx.chooseImage({
          count: 1,
          sizeType: ['original', 'compressed'],
          sourceType: ['album', 'camera'],
          success(res) {
            // console.log(res)
            // tempFilePath可以作为img标签的src属性显示图片
            const tempFilePaths = res.tempFilePaths
            // that.setData({
            //   tempFile: tempFilePaths
            // })
    
            // for (let path of res.tempFilePaths) {
            wx.uploadFile({
              url: api.UpdataWxCode,
              filePath: tempFilePaths[0],
              name: 'file',
              formData: {
                'paytype': 1,
                "type": 'cacher'
    
              },
              header: {
                'Content-Type': 'multipart/form-data',
                'X-Requested-With': 'XMLHttpRequest',
                'user-token': wx.getStorageSync('user_token'),
              },
              responseType: 'text',
              success: (res) => {
                // console.log(res, '服务器返回的微信图片')
                let image_data = res.data;
                let image_src = JSON.parse(image_data);
                that.setData({
                  // tempFile: image_src.data.src
                  tempFile: image_src.data.src
                })
              }
            })
            // }
          }
        })
      },
  • 相关阅读:
    大规模机器学习
    机器学习之推荐系统
    SVM实现邮件分类
    机器学习之异常检测
    降维算法学习
    手写数字识别实现
    动态规划训练之十七
    概率期望训练之三
    数据结构训练之四
    绵阳东辰国际test201910.25
  • 原文地址:https://www.cnblogs.com/xiaoxiaoxun/p/12083336.html
Copyright © 2011-2022 走看看