lige
2024-03-05 247493f0980f703d163620ccc139b25927c28f8f
ltkj-admin/src/main/java/com/ltkj/web/controller/app/WxloginController.java
@@ -1,5 +1,6 @@
package com.ltkj.web.controller.app;
import cn.hutool.core.date.DateTime;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@@ -25,6 +26,7 @@
import org.aspectj.bridge.MessageWriter;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;
import sun.misc.BASE64Decoder;
@@ -71,6 +73,7 @@
    /**
     * 小程序登录
     *
     * @param code 小程序wx.login返回的临时凭证
     * @return
     */
@@ -135,6 +138,7 @@
        Wxuser one = wxuserService.getOne(wq);
        return AjaxResult.success(one);
    }
    /**
     * 微信手机号码绑定
     */
@@ -191,6 +195,7 @@
    /**
     * 发送请求用code换取sessionKey和相关信息
     *
     * @param code
     * @return
     */
@@ -257,7 +262,6 @@
        }
        return null;
    }
    /**
@@ -346,5 +350,27 @@
        return response;
    }
    @PostMapping("/wx/wxbindphone")
    @ApiOperation("手动绑定手机号接口")
    @Transactional
    public AjaxResult wxbindphone(@RequestParam @ApiParam(value = "openId") String openId,
                                  @RequestParam @ApiParam(value = "phone") String phone) {
        LambdaQueryWrapper<Wxuser> wq = new LambdaQueryWrapper<>();
        wq.eq(Wxuser::getOpenid, openId);
        Wxuser one = wxuserService.getOne(wq);
        if (one!=null){
            one.setPhone(phone);
            one.setUpdateTime(new DateTime());
            final boolean b = wxuserService.updateById(one);
            if (b){
                return AjaxResult.success("绑定成功!");
            }
        }
        return AjaxResult.error("绑定失败!");
    }
}