public void TestInit() { IdentityParam identityParam = new IdentityParam() { IdentityType = "CERT_INFO", CertType = "IDENTITY_CARD", CertName = "张三", CertNo = "513901198008089876" }; MerchantConfig merchantConfig = new MerchantConfig() { ReturnUrl = "www.taobao.com" }; AlipayUserCertifyOpenInitializeResponse response = Factory.Member.Identification().Init( Guid.NewGuid().ToString(), "FACE", identityParam, merchantConfig); Assert.AreEqual(response.Code, "10000"); Assert.AreEqual(response.Msg, "Success"); Assert.IsNull(response.SubCode); Assert.IsNull(response.SubMsg); Assert.NotNull(response.HttpBody); Assert.NotNull(response.CertifyId); }
public AlipayUserCertifyOpenInitializeResponse Init(string outerOrderNo, string bizCode, IdentityParam identityParam, MerchantConfig merchantConfig) { identityParam.Validate(); merchantConfig.Validate(); Dictionary <string, object> runtime_ = new Dictionary <string, object> { { "ignoreSSL", this._kernel.GetConfig("ignoreSSL") }, { "httpProxy", this._kernel.GetConfig("httpProxy") }, { "connectTimeout", 15000 }, { "readTimeout", 15000 }, { "retry", new Dictionary <string, int?> { { "maxAttempts", 0 }, } }, }; TeaRequest _lastRequest = null; Exception _lastException = null; long _now = System.DateTime.Now.Millisecond; int _retryTimes = 0; while (TeaCore.AllowRetry((IDictionary)runtime_["retry"], _retryTimes, _now)) { if (_retryTimes > 0) { int backoffTime = TeaCore.GetBackoffTime((IDictionary)runtime_["backoff"], _retryTimes); if (backoffTime > 0) { TeaCore.Sleep(backoffTime); } } _retryTimes = _retryTimes + 1; try { TeaRequest request_ = new TeaRequest(); Dictionary <string, string> systemParams = new Dictionary <string, string> { { "method", "alipay.user.certify.open.initialize" }, { "app_id", this._kernel.GetConfig("appId") }, { "timestamp", this._kernel.GetTimestamp() }, { "format", "json" }, { "version", "1.0" }, { "alipay_sdk", this._kernel.GetSdkVersion() }, { "charset", "UTF-8" }, { "sign_type", this._kernel.GetConfig("signType") }, { "app_cert_sn", this._kernel.GetMerchantCertSN() }, { "alipay_root_cert_sn", this._kernel.GetAlipayRootCertSN() }, }; Dictionary <string, object> bizParams = new Dictionary <string, object> { { "outer_order_no", outerOrderNo }, { "biz_code", bizCode }, { "identity_param", identityParam }, { "merchant_config", merchantConfig }, }; Dictionary <string, string> textParams = new Dictionary <string, string>() { }; request_.Protocol = this._kernel.GetConfig("protocol"); request_.Method = "POST"; request_.Pathname = "/gateway.do"; request_.Headers = new Dictionary <string, string> { { "host", this._kernel.GetConfig("gatewayHost") }, { "content-type", "application/x-www-form-urlencoded;charset=utf-8" }, }; request_.Query = this._kernel.SortMap(TeaConverter.merge <string> ( new Dictionary <string, string>() { { "sign", this._kernel.Sign(systemParams, bizParams, textParams, this._kernel.GetConfig("merchantPrivateKey")) }, }, systemParams, textParams )); request_.Body = TeaCore.BytesReadable(this._kernel.ToUrlEncodedRequestBody(bizParams)); _lastRequest = request_; TeaResponse response_ = TeaCore.DoAction(request_, runtime_); Dictionary <string, object> respMap = this._kernel.ReadAsJson(response_, "alipay.user.certify.open.initialize"); if (this._kernel.IsCertMode()) { if (this._kernel.Verify(respMap, this._kernel.ExtractAlipayPublicKey(this._kernel.GetAlipayCertSN(respMap)))) { return(TeaModel.ToObject <AlipayUserCertifyOpenInitializeResponse>(this._kernel.ToRespModel(respMap))); } } else { if (this._kernel.Verify(respMap, this._kernel.GetConfig("alipayPublicKey"))) { return(TeaModel.ToObject <AlipayUserCertifyOpenInitializeResponse>(this._kernel.ToRespModel(respMap))); } } throw new TeaException(new Dictionary <string, string> { { "message", "验签失败,请检查支付宝公钥设置是否正确。" }, }); } catch (Exception e) { if (TeaCore.IsRetryable(e)) { _lastException = e; continue; } throw e; } } throw new TeaUnretryableException(_lastRequest, _lastException); }