Пример #1
0
        /// <summary>
        /// 出金操作--通联支付
        /// </summary>
        /// <param name="setAccountName">收款方账户姓名</param>
        /// <param name="setAccountNo">收款方账户银行卡号</param>
        /// <param name="setAccountType">收款方账户类型,固定值,可取值:PERSONAL代表个人账户 ENTERPRISE代表企业账户</param>
        /// <param name="setAmt">金额,正整数,精确到分。例如,票款为1280元,则表示为“128000”</param>
        /// <param name="setBankName">收款方开户行名称(精确到支行,比如中国工商银行上海市浦东大道支行)</param>
        /// <param name="setBankNo">收款方开户行行号(电子联行号)可空</param>
        private static RequestResult allinpayMethod(string setAccountName, string setAccountNo, string setAccountType, string setAmt, string setBankName, string setBankNo)
        {
            RequestResult requesResult = new RequestResult();
            // 第一步,设置环境数据
            Env env = new Env();
            //外网测试地址
            env.setServerUrl(ConfigurationManager.AppSettings["url"]);
            env.setAllinfinaceCertificatePath(ConfigurationManager.AppSettings["TLCert"]);
            env.setMerchantCertificatePath(ConfigurationManager.AppSettings["cer"]);
            env.setMerchantKeyStorePath(ConfigurationManager.AppSettings["pfx"]);

            env.setMerchantKeyStoreType(Constant.KEY_STORE_TYPE_PKCS12);
            env.setMerchantKeyStorePassword(ConfigurationManager.AppSettings["password"]);
            //商人证书别名
            env.setMerchantCertificateAlias("test");
            // 第二步,设置交易数据
            for (int i = 0; i < 1; i++)
            {

                AgentpayRequest request = new AgentpayRequest();
                AgentpayRequestEnvelope envelope = new AgentpayRequestEnvelope();
                Head head = new Head();
                // 默认utf-8
                head.setCharset("UTF-8");
                head.setVersion("v1.0.7.1");
                envelope.setHead(head);
                AgentpayRequestBody body = new AgentpayRequestBody();
                AgentpayRequestInfo info = new AgentpayRequestInfo();
                string strNo = ConfigurationManager.AppSettings["merchantId"];
                info.setMchtBatchNo(strNo + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                info.setMchtId(strNo);

                List<IRecord> records = new List<IRecord>();
                for (int ii = 0; ii < 1; ii++)
                {
                    AgentpayRequestRecord record = new AgentpayRequestRecord();
                    record.setMchtOrderNo(strNo + "Detail-" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ii);
                    record.setAccountName(setAccountName);
                    record.setAccountNo(setAccountNo);
                    record.setAccountType(setAccountType);
                    record.setAmt(long.Parse(setAmt));
                    record.setBankName(setBankName);
                    record.setBankNo(setBankNo);
                    records.Add(record);
                }
                body.setInfo(info);
                body.setRecords(records);
                envelope.setBody(body);
                request.setEnvelope(envelope);
                Sign sign = new Sign();
                sign.setSignType("1");
                request.setSign(sign);

                // 第三步,调用支付请求服务,获得支付响应
                try
                {
                    AgentpayResponse response = AgentpayService.pay((IBatch)request, env);
                    for (int j = 0; j < response.getEnvelope().getBody().getRecords().Count(); j++)
                    {
                        //ElementAt(j)替换get(j)
                        AgentpayResponseRecord rr = (AgentpayResponseRecord)response.getEnvelope().getBody().getRecords().ElementAt(j);
                        string code = rr.getResponseCode();
                        if (code == "E0000" || code == "R1001" || code == "R1000")
                        {
                            requesResult.IsSuccess = true;
                            requesResult.ErrMsg = rr.getResponseMsg();
                        }
                        else
                        {
                            requesResult.IsSuccess = false;
                            requesResult.ErrMsg = rr.getResponseMsg();
                        }

                    }
                }
                catch (BatchResolveException e)
                {
                    requesResult.IsSuccess = false;
                    requesResult.ErrMsg = "   异常     " + e.Message;
                }
            }
            return requesResult;
        }
Пример #2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="MchtOrderNo">订单号</param>
        /// <param name="AccountName">收款方姓名</param>
        /// <param name="AccountNo">收款方账号</param>
        /// <param name="Amt">金额,正整数,精确到分。例如,票款为1280元,则表示为“128000”</param>
        /// <param name="BankName">收款方开户行名称(精确到支行,比如中国工商银行上海市浦东大道支行)</param>
        /// <param name="BankNo">银行code</param>
        /// <returns></returns>
        public static string SetMoneyOrder(string MchtOrderNo, string AccountName, string AccountNo, int Amt, string BankName, string BankNo)
        {
            Env env = new Env();
            //外网测试地址
            env.setServerUrl(tServerUrl);
            env.setAllinfinaceCertificatePath(AllinfinaceCertificatePath);
            env.setMerchantCertificatePath(MerchantCertificatePath);
            env.setMerchantKeyStorePath(MerchantKeyStorePath);

            env.setMerchantKeyStoreType(Constant.KEY_STORE_TYPE_PKCS12);
            env.setMerchantKeyStorePassword(password);
            env.setMerchantCertificateAlias(MerchantCertificateAlias);
            // 第二步,设置交易数据
            //for (int i = 0; i < 1; i++)
            //{

            AgentpayRequest request = new AgentpayRequest();
            AgentpayRequestEnvelope envelope = new AgentpayRequestEnvelope();
            Head head = new Head();
            // 默认utf-8
            head.setCharset("UTF-8");
            head.setVersion("v1.0.7.1");
            envelope.setHead(head);
            AgentpayRequestBody body = new AgentpayRequestBody();
            AgentpayRequestInfo info = new AgentpayRequestInfo();
            info.setMchtBatchNo(MchtOrderNo);//商户批次号,全局唯一
            info.setMchtId(CZmerchantId);//商户号

            List<IRecord> records = new List<IRecord>();
            //for (int ii = 0; ii < 1; ii++)
            //{
            AgentpayRequestRecord record = new AgentpayRequestRecord();
            record.setMchtOrderNo(MchtOrderNo);//商户订单号,建议全局唯一,至少同一商户批次内唯一
            record.setAccountName(AccountName);//收款方姓名
            record.setAccountNo(AccountNo);//收款方账号
            record.setAccountType("PERSONAL");//收款方账户类型,固定值,可取值:PERSONAL代表个人账户  ENTERPRISE代表企业账户

            record.setAmt(Amt);//金额,正整数,精确到分。例如,票款为1280元,则表示为“128000”
            record.setBankName(BankName);//收款方开户行名称(精确到支行,比如中国工商银行上海市浦东大道支行)
            record.setBankNo(BankNo);//收款方开户行行号(电子联行号)
            records.Add(record);
            //}
            body.setInfo(info);
            body.setRecords(records);
            envelope.setBody(body);
            request.setEnvelope(envelope);
            Sign sign = new Sign();
            sign.setSignType("1");
            request.setSign(sign);

            // 第三步,调用支付请求服务,获得支付响应
            try
            {
                AgentpayResponse response = AgentpayService.pay((IBatch)request, env);
                string a = "";
                string a1 = response.getSign().getSignContent();
                string a2 = ((AgentpayResponseInfo)((AgentpayResponseBody)((AgentpayResponseEnvelope)response.getEnvelope()).getBody()).getInfo()).getMchtId();
                string a3 = ((AgentpayResponseInfo)((AgentpayResponseBody)((AgentpayResponseEnvelope)response.getEnvelope()).getBody()).getInfo()).getTotalCnt() + "";
                string a4 = ((AgentpayResponseInfo)((AgentpayResponseBody)((AgentpayResponseEnvelope)response.getEnvelope()).getBody()).getInfo()).getResponseCode();
                string a5 = ((AgentpayResponseInfo)((AgentpayResponseBody)((AgentpayResponseEnvelope)response.getEnvelope()).getBody()).getInfo()).getResponseMsg();
                a = a1 + "\r\n" + a2 + "\r\n" + a3 + "\r\n" + a4 + "\r\n" + a5 + "\r\n";

                for (int j = 0; j < response.getEnvelope().getBody().getRecords().Count(); j++)
                {
                    AgentpayResponseRecord rr = (AgentpayResponseRecord)response.getEnvelope().getBody().getRecords().ElementAt(j);
                    string a6 = rr.getResponseCode() + ":" + rr.getResponseMsg();
                    a = a + "\r\n" + a6;
                    //Console.WriteLine(rr.getResponseCode() + ":" + rr.getResponseMsg());

                }
                return a5;
            }
            catch
            {
                return "异常";
            }
            //}
        }