|
@@ -544,79 +544,36 @@ class User extends Api
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 微信注册来的,绑定手机号
|
|
|
+ * 手机注册来的,绑定微信
|
|
|
*
|
|
|
* @ApiMethod (POST)
|
|
|
- * @param string $mobile 手机号
|
|
|
- * @param string $captcha 验证码
|
|
|
+ * @param string $wechat_openid
|
|
|
*/
|
|
|
- /*public function bindopenid()
|
|
|
+ public function bindopenid()
|
|
|
{
|
|
|
- $user = $this->auth->getUser();
|
|
|
$wechat_openid = $this->request->request('wechat_openid');
|
|
|
+ if (!$wechat_openid) {
|
|
|
+ $this->error(__('Invalid parameters'));
|
|
|
+ }
|
|
|
|
|
|
if(!empty($this->auth->wechat_openid)){
|
|
|
$this->error('已经绑定了微信号');
|
|
|
}
|
|
|
- if (!$wechat_openid) {
|
|
|
- $this->error(__('Invalid parameters'));
|
|
|
- }
|
|
|
|
|
|
- if (\app\common\model\User::where('wechat_openid', $wechat_openid)->find()) {
|
|
|
+ $otherUserWhere['wechat_openid'] = $wechat_openid;
|
|
|
+ $otherUserWhere['id'] = ['neq',$this->auth->id];
|
|
|
+ if (\app\common\model\User::where($otherUserWhere)->find()) {
|
|
|
$this->error('该微信号已被其他用户绑定');
|
|
|
}
|
|
|
|
|
|
+ $user = $this->auth->getUser();
|
|
|
$user->wechat_openid = $wechat_openid;
|
|
|
$user->save();
|
|
|
|
|
|
$this->success('success',$this->userInfo('return'));
|
|
|
- }*/
|
|
|
-
|
|
|
- /**
|
|
|
- * 手机注册来的,绑定微信
|
|
|
- *
|
|
|
- * @ApiMethod (POST)
|
|
|
- * @param string $wechat_openid
|
|
|
- */
|
|
|
- public function bindopenid()
|
|
|
- {
|
|
|
- Db::startTrans();
|
|
|
-
|
|
|
- $code = $this->request->param('code','');
|
|
|
- if(!$code){
|
|
|
- $this->error(__('Invalid parameters'));
|
|
|
- }
|
|
|
- //微信
|
|
|
- $wechat = new Wechat();
|
|
|
- $openid = $wechat->getOpenid($code);
|
|
|
-
|
|
|
- if(!$openid){
|
|
|
- $this->error('openid获取失败');
|
|
|
- }
|
|
|
-
|
|
|
- $user = model('User')->find($this->auth->id);
|
|
|
- if(!empty($user['wechat_openid'])/* && $openid != $user['openid']*/){
|
|
|
- $this->error('已经绑定了微信号');
|
|
|
- }
|
|
|
- $otherUserWhere['wechat_openid'] = $openid;
|
|
|
- $otherUserWhere['id'] = ['neq',$this->auth->id];
|
|
|
- $otherUser = model('User')->where($otherUserWhere)->find();
|
|
|
- if (!empty($otherUser)) {
|
|
|
- $this->error('该微信已被其他用户绑定过');
|
|
|
- }
|
|
|
-
|
|
|
- $user->wechat_openid = $openid;
|
|
|
- $userRes = $user->save();
|
|
|
- if (!$userRes) {
|
|
|
- $this->error('绑定微信失败');
|
|
|
- }
|
|
|
- Db::commit();
|
|
|
- $this->success('success',$this->userInfo('return'));
|
|
|
-
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 重置密码
|
|
|
*
|