Ejemplo n.º 1
0
 /**
  * @param string $im_user_id im用户id
  * @param string $im_password im密码
  * @param string $name 名字
  * @param string $nick 昵称
  * @param string $gender 性别 M: 男, F:女
  * @param array $other 参见 http://open.taobao.com/doc2/apiDetail.htm?apiId=24164
  * @return boolean
  */
 public function addImUser($im_user_id, $im_password, $name, $nick = null, $gender = null, $other = array())
 {
     if (!is_array($other)) {
         $other = array();
     }
     $req = new \OpenimUsersAddRequest();
     $userInfo = new \Userinfos();
     $userInfo->nick = $nick ? $nick : $name;
     $userInfo->icon_url = isset($other['icon_url']) ? $other['icon_url'] : null;
     $userInfo->email = isset($other['email']) ? $other['email'] : null;
     $userInfo->mobile = isset($other['mobile']) ? $other['mobile'] : null;
     $userInfo->taobaoid = isset($other['taobaoid']) ? $other['taobaoid'] : null;
     $userInfo->userid = $im_user_id;
     $userInfo->password = $im_password;
     $userInfo->remark = isset($other['remark']) ? $other['remark'] : null;
     $userInfo->extra = isset($other['extra']) ? json_encode($other['extra']) : '{}';
     $userInfo->career = isset($other['career']) ? $other['career'] : null;
     $userInfo->vip = isset($other['vip']) ? json_encode($other['vip']) : '{}';
     $userInfo->address = isset($other['address']) ? $other['address'] : null;
     $userInfo->name = $name;
     $userInfo->age = isset($other['age']) ? $other['age'] : null;
     $userInfo->gender = in_array($gender, array('M', 'F')) ? $gender : null;
     $userInfo->wechat = isset($other['wechat']) ? $other['wechat'] : null;
     $userInfo->qq = isset($other['qq']) ? $other['qq'] : null;
     $userInfo->weibo = isset($other['weibo']) ? $other['weibo'] : null;
     $req->setUserinfos(json_encode($userInfo));
     $client = $this->getClient();
     $resp = $client->execute($req);
     return true;
 }
Ejemplo n.º 2
0
function addOpenImUser($userid)
{
    global $c;
    $req = new OpenimUsersAddRequest();
    $userinfos = initUserinfos($userid);
    //$userinfos = initUserinfos($userid2);
    //echo  json_encode(array(0 => $userinfos1, 1 => $userinfos2));
    //$req->setUserinfos(json_encode(array(0 => $userinfos1, 1 => $userinfos2)));
    $req->setUserinfos(json_encode($userinfos));
    $resp = $c->execute($req);
    print_r($resp);
}
Ejemplo n.º 3
0
//cors
header("Access-Control-Allow-Origin: *");
function objectToArray($object)
{
    //对象编程数组,递归搞来搞去搞
    if (!is_object($object) && !is_array($object)) {
        return $object;
    }
    return array_map('objectToArray', (array) $object);
}
$app->get('/', function () {
    //存在的价值大概就是判断api服务有没有的拉
    echo '<h1>let barrage fly api</h1>';
});
$app->post('/register', function () use($client) {
    $requset = new OpenimUsersAddRequest();
    $userinfo = new Userinfos();
    $requestBody = json_decode(@file_get_contents('php://input'), true);
    $username = isset($requestBody['username']) && $requestBody['username'] != '' ? $requestBody['username'] : '';
    $password = isset($requestBody['password']) && $requestBody['password'] != '' ? md5($requestBody['password']) : '';
    $userinfo->userid = $username;
    $userinfo->password = $password;
    $requset->setUserinfos(json_encode($userinfo));
    $response = $client->execute($requset);
    $responseArray = objectToArray($response);
    if (isset($responseArray['uid_succ']['string']) && $responseArray['uid_succ']['string'] == $userinfo->userid) {
        //判断是否注册成功,直接返回密码,用来登录,也就是credential
        echo json_encode(array('msg' => 'success register', 'code' => 'success', 'username' => $userinfo->userid, 'password' => $userinfo->password));
    } else {
        throw new \Exception(json_encode($responseArray));
        //        echo json_encode($responseArray);
Ejemplo n.º 4
0
 public function getAnonymousUser($uid = 0)
 {
     $req = new OpenimUsersAddRequest();
     $this->setUserid($uid);
     $this->setPassword(md5($uid));
     $userinfos['email'] = $this->getEmail();
     $userinfos['mobile'] = $this->getMobile();
     $userinfos['taobaoid'] = $this->getTaobaoid();
     $userinfos['userid'] = $this->getUserid();
     $userinfos['password'] = $this->getPassword();
     $req->setUserinfos(json_encode($userinfos));
     return $this->c->execute($req);
 }