public static function tokenAction($controller, $con, $appid, $openid, $encrypt) { $da = $con; //$result = Utils::do_post_request("http://www.wefafa.com", array()); $sql = "select appkey from we_appcenter_apps where appid=?"; $ds = $da->GetData("t", $sql, array((string) $appid)); $result = ""; $json = array("error" => "bad error"); try { if (count($ds["t"]["rows"]) == 0) { $json = array("error" => "invalid appid"); } else { $appkey = $ds["t"]["rows"][0]["appkey"]; $sql = "select authkey,bind_uid from we_staff_account_bind a,we_staff b where a.bind_account=b.openid and a.bind_account=? and a.bind_type=?"; $ds = $da->GetData("tb", $sql, array((string) $openid, self::$bind_type)); if (count($ds["tb"]["rows"]) > 0) { //$api = new \Justsy\OpenAPIBundle\Controller\ApiController(); //$api->setContainer($controller->container); $code = md5($appid . $appkey); //解析autokey $bind_uid = $ds['tb']['rows'][0]["bind_uid"]; if ($encrypt == '1') { $bind_uid = DES::decrypt2($bind_uid, $appkey); } //获取携程令牌 $EmployeeNO = $bind_uid; $paraXml = '<SSOAuthRequest>' . '<Language>Chinese</Language>' . '<SSOAuth>' . '<AccessUK>' . self::$AccessUK . '</AccessUK>' . '<AccessPK>' . self::$AccessPK . '</AccessPK>' . '<EmployeeNO>' . $EmployeeNO . '</EmployeeNO>' . '</SSOAuth>' . '</SSOAuthRequest>'; $soap = new SoapClient(self::$get_token_url . "?WSDL"); $para = array("requestXMLString" => array("SSOAuthRequest" => array("Language" => "Chinese", "SSOAuth" => array("AccessUK" => self::$AccessUK, "AccessPK" => self::$AccessPK, "EmployeeNO" => $EmployeeNO)))); $para = array("requestXMLString" => $paraXml); error_reporting(E_ERROR | E_WARNING | E_PARSE); $result = $soap->SSOAuthenticaionWithXML($para); error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE); //$controller->get("logger")->err($result); $accesstoken = ''; //解析result if (isset($result->SSOAuthenticaionWithXMLResult)) { $str = $result->SSOAuthenticaionWithXMLResult; $arr1 = explode('&', $str); for ($i = 0; $i < count($arr1); $i++) { $arr2 = explode('=', $arr1[$i]); if ($arr2[0] == 'AccessToken') { $accesstoken = $arr2[1]; break; } } if (empty($accesstoken)) { $json = array("error" => "您的账号激活周期为24小时,如有疑问请拨打:010-67876363-2, 如需出行服务请拨打:400-920-0670或400-820-6699。"); } else { $json = array('token' => $accesstoken); } } else { $json = array("error" => "您的账号激活周期为24小时,如有疑问请拨打:010-67876363-2, 如需出行服务请拨打:400-920-0670或400-820-6699。"); } } else { $json = array("error" => "您的账号激活周期为24小时,如有疑问请拨打:010-67876363-2, 如需出行服务请拨打:400-920-0670或400-820-6699。"); } } } catch (\Exception $e) { $json['error'] = $e->getMessage(); } return $json; }
public static function bindAction($controller, $con, $appid, $openid, $params) { $re = array("returncode" => "0000"); try { $authcode = $params->get("auth"); $sql = "select appkey from we_appcenter_apps where appid=?"; $ds = $con->GetData("t", $sql, array((string) $appid)); if (count($ds["t"]["rows"]) == 0) { $re = array("returncode" => "9999", "msg" => "appid is not found"); } else { $appkey = $ds["t"]["rows"][0]["appkey"]; $sql = "delete from we_staff_account_bind where bind_account=? and bind_type=? and appid=?"; $con->ExecSQL($sql, array((string) $openid, self::$bind_type, $appid)); if ($params->get('encrypt') == '1') { //$authcode=DES::encrypt2($authcode,'_sddb74+'); } else { $authcode = DES::decrypt2($authcode, '_sddb74+'); } $authkey = $authcode; //DES::decrypt2($authcode,'_sddb74+'); $bind_uid = json_decode($authkey, true); $bind_uid = $bind_uid['userid']; $authcode = DES::encrypt2($authcode, $appkey); $sql = "insert into we_staff_account_bind(bind_account,appid,bind_uid,authkey,bind_type,bind_created)values(?,?,?,?,?,now())"; $con->ExecSQL($sql, array((string) $openid, (string) $appid, (string) $bind_uid, (string) $authcode, self::$bind_type)); } } catch (\Exception $e) { $re = array("returncode" => "9999", "msg" => $e->getMessage()); } return $re; }
public function getauthAction($openid, $appid) { $da = $this->get("we_data_access"); $request = $this->get("request"); $re = array("returncode" => "0000"); //$bx_data=$request->get("data"); try { $bind_type = $request->get('bind_type'); if ($bind_type == '') { return $this->responseJson(array("returncode" => "9999", "msg" => 'bind_type无效'), $request->get('jsoncallback')); } $sql = "select appkey from we_appcenter_apps where appid=?"; $ds = $da->GetData("t", $sql, array((string) $appid)); if (count($ds["t"]["rows"]) == 0) { $re = array("returncode" => "9999", "msg" => "appid is not found"); } else { $appkey = $ds["t"]["rows"][0]["appkey"]; $isdecrypt = $request->get("decrypt"); $sql = "select authkey,bind_uid from we_staff_account_bind where bind_account=? and bind_type=? and appid=?"; $ds = $da->GetData("t", $sql, array((string) $openid, (string) $bind_type, $appid)); if ($ds['t']['recordcount'] == 0) { $re = array("returncode" => "0000", "msg" => "未获取到绑定信息"); return $this->responseJson($re); } $authkey = $ds["t"]["rows"][0]["authkey"]; $authkey = DES::decrypt2($authkey, $appkey); if ($isdecrypt == "1") { //$authkey=DES::decrypt2($authkey,$appkey); } $re["code"] = $authkey; } } catch (\Exception $e) { $re = array("returncode" => "9999", "msg" => $e->getMessage()); } return $this->responseJson($re); }