wxml界面

 

图片上传

<button bindtap="image" type="primary">上传图片</button>

<image wx:for="{{imageList}}" src="{{item.img}}" name="img"></image>

js界面

image:function()
{
  wx.chooseImage({
    count: 1,
    sizeType: ['original','compressed'],
    sourceType: ['album','camera'],
    success: (result)=>{
      // console.log(result);
          let tempFilePaths=result.tempFilePaths;
           wx.uploadFile({
            url: 'http://www.day8.com/api/image',
            filePath:tempFilePaths[0],
            name: 'image',
            formData: {},
            success: (res)=>{
              // console.log(res);
              let name =JSON.parse(res.data);
              this.data.imageList.push(name.data.path);
              this.setData({
                imageList:this.data.imageList
              })
            },
            fail: ()=>{},
            complete: ()=>{}
          });
    },
    fail: ()=>{},
    complete: ()=>{}
  });
},

 laravel8

  public function image()
    {
        $file=$_FILES;
        $img=$file['image']['tmp_name'];
        $suffix=strtolower(substr($file['image']['name'],strpos($file['image']['name'],'.')));
        $fileName=md5($file['image']['name'].date('s'.time()).rand(1,99999));
        $fileName.=$suffix;
        // 需要填写你的 Access Key 和 Secret Key
        $accessKey ="ZaNQA651RMh49VZ4dh5w7DMonBaDPw5Wp4tyITUe";
        $secretKey ="UT59YbeYjVKrtaPsfl6sGOJGwgtLNAfDpeuL_3gx";
        $bucket = "shihao1";
        // 构建鉴权对象
        $auth = new Auth($accessKey,$secretKey);
        // 生成上传 Token
        $token = $auth->uploadToken($bucket);
        // 初始化 UploadManager 对象并进行文件的上传。
        $uploadMgr = new UploadManager();
        // 调用 UploadManager 的 putFile 方法进行文件的上传。
        list($ret, $err) = $uploadMgr->putFile($token, $fileName, $img);

        if ($err !== null) {
            return response()->json(['code'=>500,'msg'=>'上传失败']);
        }
        $imageUrl="http://rcycwkuy1.hd-bkt.clouddn.com/".$fileName;

        return response()->json(['code'=>200,'msg'=>'success','data'=>['path'=>$imageUrl]]);
    }

地图选点

wxml

 <input type="text" name="map" >{{address}}</input>
 <button bindtap="address">地图选点</button>

 js

wx.chooseLocation 微信位置插件

address(evt){
wx.chooseLocation({
  success:(res)=>{
    console.log(res);
    this.setData({
      address:res.name
    })
  }
})
},

 

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐