diff --git a/backstage/application/api/controllers/api/Applet.php b/backstage/application/api/controllers/api/Applet.php index 1052830..6057c46 100644 --- a/backstage/application/api/controllers/api/Applet.php +++ b/backstage/application/api/controllers/api/Applet.php @@ -180,4 +180,33 @@ class Applet extends REST_Controller { ) ), REST_Controller::HTTP_OK); } + + public function updateAppletOpenid_post(){ + $user_id = $this->user->id; + $uid = $this->input->post("uid", true); + if($user_id != $uid){ + $this->response(array( + 'status' => 0, + 'message' => 'token和uid不匹配', + + ), REST_Controller::HTTP_OK); + } + $applet_openid = $this->input->post("applet_openid", true); + + // 先清空关于这个openid的数据 + $this->User_model->clearAppletOpenid($applet_openid); + + $res = $this->User_model->update_user(array('applet_openid' => $applet_openid), $user_id); + if($res){ + $this->response(array( + 'status' => 1, + 'message' => '更新成功', + ), REST_Controller::HTTP_OK); + }else{ + $this->response(array( + 'status' => 0, + 'message' => '更新失败', + ), REST_Controller::HTTP_OK); + } + } } diff --git a/backstage/application/api/models/User_model.php b/backstage/application/api/models/User_model.php index 73b0f74..471ef61 100644 --- a/backstage/application/api/models/User_model.php +++ b/backstage/application/api/models/User_model.php @@ -1174,4 +1174,11 @@ class User_model extends CI_Model $rs = $this->db->query($sql)->result_array(); return $rs[0]; } + + // 清空指定applet_openid + public function clearAppletOpenid($openid){ + $this->db->where('applet_openid', $openid); + $data = array('applet_openid' => null); + return $this->db->update('tb_user', $data); + } } diff --git a/show/get.php b/show/get.php index 64e1674..bd00716 100644 --- a/show/get.php +++ b/show/get.php @@ -228,7 +228,7 @@ if($act == 'applet_unifiedorder') { if($isjsapi) { $openid = $user['applet_openid']; if(!$openid) { - echoRs(0, '非小程序注册用户!不能使用小程序支付!'); + echoRs(0, '获取openid失败,请在小程序里重新登录再试!'); } } $host = $_SERVER['HTTP_HOST'];