• 微信发起摄像头接口请求 上传头像 图片


    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
                })
              }
            })
            // }
          }
        })
      },
  • 相关阅读:
    016_异步处理_Future
    013_REST Service
    012_介绍Soap&Rest
    011_Validation Rule about Time
    010_Soap update
    006_Salesforce Sharing 使用说明
    005_重写 Standard Delete Button
    004_Intelij 使用,Anonymous Apex
    003_关于IntellJ IDE 2016 1. 4的使用
    Dashborad 上显示出错
  • 原文地址:https://www.cnblogs.com/xiaoxiaoxun/p/12083336.html
Copyright © 2020-2023  润新知