3335 代码维护,去掉ios 敏感的unity.www接口,影响聊天语音翻译
| | |
| | | public const string defaultHttpContentType = "application/x-www-form-urlencoded";
|
| | | public const string jsonHttpContentType = "application/json ; charset=utf-8";
|
| | |
|
| | | public void RequestWWW(string _url, int _retry = 3, Action<bool, string> _result = null)
|
| | | {
|
| | | StartCoroutine(Co_RequestWWW(_url, null, _retry, _result));
|
| | | }
|
| | |
|
| | | public void RequestWWW(string _url, IDictionary<string, string> _parameters, int _retry = 3, Action<bool, string> _result = null)
|
| | | {
|
| | | StartCoroutine(Co_RequestWWW(_url, _parameters, _retry, _result));
|
| | | }
|
| | |
|
| | | IEnumerator Co_RequestWWW(string _url, IDictionary<string, string> _parameters, int _retry = 3, Action<bool, string> _result = null)
|
| | | {
|
| | | if (_url == null || _url.Length == 0)
|
| | | {
|
| | | DebugEx.LogError("PHPDataComm post 参数有错");
|
| | | if (_result != null)
|
| | | {
|
| | | _result(false, string.Empty);
|
| | | _result = null;
|
| | | }
|
| | | yield break;
|
| | | }
|
| | |
|
| | | int i = 0;
|
| | | bool isSuccess = false;
|
| | |
|
| | | byte[] data = null;
|
| | | if (_parameters != null)
|
| | | {
|
| | | data = Encoding.UTF8.GetBytes(HashtablaToString(_parameters));
|
| | | }
|
| | |
|
| | | var PostData = data == null ? new WWW(_url) : new WWW(_url, data);
|
| | |
|
| | | while (!PostData.isDone)
|
| | | {
|
| | | yield return null;
|
| | | }
|
| | |
|
| | | if (PostData.error != null)
|
| | | {
|
| | | Debug.LogErrorFormat("WWW 数据通信,请求数据失败:{0},已经尝试,{1},次", PostData.error, i);
|
| | | }
|
| | | else
|
| | | {
|
| | | if (!string.IsNullOrEmpty(PostData.text))
|
| | | {
|
| | | DebugEx.LogFormat("WWW 数据通信,请求数据成功:{0}", PostData.text);
|
| | | isSuccess = true;
|
| | | if (_result != null)
|
| | | {
|
| | | _result(true, PostData.text);
|
| | | _result = null;
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | if (!isSuccess)
|
| | | {
|
| | | if (_result != null)
|
| | | {
|
| | | _result(false, string.Empty);
|
| | | _result = null;
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | public void RequestHttpPost(string _url, IDictionary<string, string> _parameters, string _contentType, int _retry = 3, Action<bool, string> _result = null)
|
| | | {
|
| | | var content = HashtablaToString(_parameters);
|
| | |
| | | public void RequestGetToken()
|
| | | {
|
| | | var url = "https://openapi.baidu.com/oauth/2.0/token?grant_type=client_credentials" + "&client_id=" + apiKey + "&client_secret=" + secretKey;
|
| | | HttpRequest.Instance.RequestWWW(url, 2, OnGetToken);
|
| | | HttpRequest.Instance.RequestHttpGet(url, HttpRequest.defaultHttpContentType, 2, OnGetToken);
|
| | | }
|
| | |
|
| | | private void OnGetToken(bool _ok, string _result)
|