c#.net 支付宝接口-凯发app官方网站

凯发app官方网站-凯发k8官网下载客户端中心 | | 凯发app官方网站-凯发k8官网下载客户端中心
  • 博客访问: 2581
  • 博文数量: 1
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 10
  • 用 户 组: 普通用户
  • 注册时间: 2015-09-17 22:29
文章分类

(1)

  • (1)
文章存档

(1)

我的朋友
最近访客
相关博文
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·

分类: windows

2015-11-24 12:59:13

原文地址: 作者:

生成url链接
复制  保存
using system;
using system.data;
using system.configuration;
using system.collections;
using system.web;
using system.web.security;
using system.web.ui;
using system.web.ui.webcontrols;
using system.web.ui.webcontrols.webparts;
using system.web.ui.htmlcontrols;
using system.text;
public partial class pay : system.web.ui.page
{
    protected void page_load(object sender, eventargs e)
    {
        encoding gb2312 = encoding.getencoding("gb2312");
        response.contentencoding = gb2312;
        request.contentencoding = gb2312;
    }
    protected void imagebutton1_click(object sender, imageclickeventargs e)
    {
        if (request.cookies[formsauthentication.formscookiename] != null)
        {
            vlike_db_read a = new vlike_db_read();
            string zfb_ddh = a.get_zfb_id(membership.getuser().username, convert.toint32(dropdownlist1.selectedvalue));
            response.redirect(img("0001", "包月", "影视包月  10元/月", zfb_ddh, "10.00", membership.getuser().username.toupper(), dropdownlist1.selectedvalue));
        }
        else
        {
            response.write("");
        }
    }
    private string img(string strcmd, string strsub, string strsubinfo, string strid, string strmoney, string struser, string strnum)
    {
        string strselleremail = "341081@qq.com";          //卖家支付宝帐号
        string strac = "";            //卖家支付宝安全校验码
        string interface_url = "https://";
        string strcmd = strcmd;           //命令字
        string strsubject = strsub;       //商品名
        string strbody = strsubinfo;      //商品描述
        string strorder_no = strid;       //商户订单号
        string strprice = strmoney;       //商品单价 0.01~50000.00
        string rurl = "http://";          //商品展示网址
        string strtype = "2";             //type支付类型    1:商品购买2:服务购买3:网络拍卖4:捐赠
        string strnumber = strnum;        //购买数量
        string strtransport = "3";        //发货方式        1:平邮2:快递3:虚拟物品
        string strordinary_fee = "";      //平邮运费
        string strexpress_fee = "";       //快递运费
        string strreadonly = "true";      //交易信息是否只读
        string strbuyer_msg = "";         //买家给卖家的留言

        string strbuyer = "";             //买家email
        string strbuyer_name = struser;   //买家姓名
        string strbuyer_address = "";     //买家地址
        string strbuyer_zipcode = "";     //买家邮编
        string strbuyer_tel = "";         //买家电话号码
        string strbuyer_mobile = "";      //买家手机号码
        string strpartner = "";           //凯发k8官网下载客户端中心的合作伙伴id    保留字段

        return creat;
    }
    private string creat
    {   //以下参数值不能留空

        string str2createac = "";
        str2createac  = "cmd"   strcmd   "subject"   strsubject;
        str2createac  = "body"   strbody;
        str2createac  = "order_no"   strorder_no;
        str2createac  = "price"   strprice;
        str2createac  = "url"   rurl;
        str2createac  = "type"   strtype;
        str2createac  = "number"   strnumber;
        str2createac  = "transport"   strtransport;
        str2createac  = "ordinary_fee"   strordinary_fee;
        str2createac  = "express_fee"   strexpress_fee;
        str2createac  = "readonly"   strreadonly;
        str2createac  = "buyer_msg"   strbuyer_msg;
        str2createac  = "seller"   strselleremail;
        str2createac  = "buyer"   strbuyer;
        str2createac  = "buyer_name"   strbuyer_name;
        str2createac  = "buyer_address"   strbuyer_address;
        str2createac  = "buyer_zipcode"   strbuyer_zipcode;
        str2createac  = "buyer_tel"   strbuyer_tel;
        str2createac  = "buyer_mobile"   strbuyer_mobile;
        str2createac  = "partner"   strpartner;
        str2createac  = strac;
        string accode = getmd5(str2createac);
        string parameter = "";
        parameter  = interface_url   strselleremail   "?cmd="   strcmd;
        parameter  = "&subject="   server.urlencode(strsubject);
        parameter  = "&body="   server.urlencode(strbody);
        parameter  = "&order_no="   strorder_no;
        parameter  = "&url="   rurl;
        parameter  = "&price="   strprice;
        parameter  = "&type="   strtype;
        parameter  = "&number="   strnumber;
        parameter  = "&transport="   strtransport;
        parameter  = "&ordinary_fee="   strordinary_fee;
        parameter  = "&express_fee="   strexpress_fee;
        parameter  = "&readonly="   strreadonly;
        parameter  = "&buyer_msg="   strbuyer_msg;
        parameter  = "&buyer="   strbuyer;
        parameter  = "&buyer_name="   server.urlencode(strbuyer_name);
        parameter  = "&buyer_address="   strbuyer_address;
        parameter  = "&buyer_zipcode="   strbuyer_zipcode;
        parameter  = "&buyer_tel="   strbuyer_tel;
        parameter  = "&buyer_mobile="   strbuyer_mobile;
        parameter  = "&partner="   strpartner;
        parameter  = "&ac="   accode;
        return parameter;
    }
    private static string getmd5(string s)
    {
        system.security.cryptography.md5 md5 = new system.security.cryptography.md5cryptoserviceprovider();
        byte[] t = md5.computehash(system.text.encoding.getencoding("gb2312").getbytes(s));
        system.text.stringbuilder sb = new system.text.stringbuilder(32);
        for (int i = 0; i < t.length; i  )
        {
            sb.append(t[i].tostring("x").padleft(2, '0'));
        }
        return sb.tostring();
    }
}

接收信息并进行相应操作
复制  保存
<%@ page language="c#" %>
<%@ import namespace="system.data.sqlclient" %>
<%@ import namespace="system.data" %>
<%@ import namespace="system.web" %>
<%@ import namespace="system.io" %>
<%@ import namespace="system.net" %>
<%@ import namespace="system.text" %>
<%@ import namespace="system.security.cryptography" %>
<script type="text/c#" runat="server">
private string returntxt = "n";              //返回给支付宝通知接口的结果
private string alipaynotifyurl = "http://notify.alipay.com/trade/notify_query.do?";    //支付宝查询接口url
private string myalipayemail = "341081@qq.com";            //商户的支付宝email
private string constpaysecuritycode = "";                  //码
private sqlconnection conn = new sqlconnection();
private string getmd5(string s)
{
    system.security.cryptography.md5 md5 = new system.security.cryptography.md5cryptoserviceprovider();
    byte[] t = md5.computehash(system.text.encoding.getencoding("gb2312").getbytes(s));
    stringbuilder sb = new stringbuilder(32);
    for (int i = 0; i < t.length; i  )
    {
        sb.append(t[i].tostring("x").padleft(2, '0'));
    }
    return sb.tostring();
}
private string get_http(string a_strurl, int timeout)
{
    string strresult;
    try
    {
        system.net.httpwebrequest myreq = (system.net.httpwebrequest) system.net.httpwebrequest.create(a_strurl);
        myreq.timeout = timeout;
        system.net.httpwebresponse httpwresp = (system.net.httpwebresponse) myreq.getresponse();
        stream mystream = httpwresp.getresponsestream();
        streamreader sr = new streamreader(mystream, system.text.encoding.default);
        system.text.stringbuilder strbuilder = new system.text.stringbuilder();
        while (-1 != sr.peek())
        {
            strbuilder.append(sr.readline()   "\r\n");
        }
        strresult = strbuilder.tostring();
    }
    catch (exception exp)
    {
        strresult = "错误:"   exp.message;
    }
    return strresult;
}
public void send(string sql)
{
    string dbconn = "data source=127.0.0.1;uid=cm;pwd=fallenangel;database=text";
    conn = new sqlconnection(dbconn);
    conn.open();
    sqlcommand cmd = new sqlcommand(sql, conn);
    int aa = cmd.executenonquery();
    conn.close();
}
private void page_load(object sender, system.eventargs e)
{
    //检查支付宝通知接口传递过来的参数是否合法
    string msg_id = system.web.httpcontext.current.request["msg_id"];
    string order_no = system.web.httpcontext.current.request["order_no"];
    string gross = system.web.httpcontext.current.request["gross"];
    string buyer_email = system.web.httpcontext.current.request["buyer_email"];
    string buyer_name = system.web.httpcontext.current.request["buyer_name"];
    string buyer_address = system.web.httpcontext.current.request["buyer_address"];
    string buyer_zipcode = system.web.httpcontext.current.request["buyer_zipcode"];
    string buyer_tel = system.web.httpcontext.current.request["buyer_tel"];
    string buyer_mobile = system.web.httpcontext.current.request["buyer_mobile"];
    string action = system.web.httpcontext.current.request["action"];
    string s_date = system.web.httpcontext.current.request["date"];
    string ac = system.web.httpcontext.current.request["ac"];
    string notify_type = system.web.httpcontext.current.request["notify_type"];
    alipaynotifyurl = alipaynotifyurl   "msg_id="   msg_id   "&email="   myalipayemail   "&order_no="   order_no;
    //获取支付宝atn返回结果,true和false都是正确的订单信息,invalid 是无效的
    string responsetxt = get_http(alipaynotifyurl, 120000);
    string str = "msg_id"   msg_id   "order_no"   order_no   "gross"   gross   "buyer_email"   buyer_email   "buyer_name"   buyer_name   "buyer_address"   buyer_address   "buyer_zipcode"   buyer_zipcode   "buyer_tel"   buyer_tel   "buyer_mobile"   buyer_mobile   "action"   action   "date"   s_date   constpaysecuritycode;
    string ac_code = getmd5(str);
    if (action == "test") //支付宝接口测试是否有效
    {
        returntxt = "y";
    }
    if (action == "sendoff")  //发货通知
    {
        if (responsetxt.substring(0, 4) == "true" 
            || responsetxt.substring(0, 4) == "fals")//atn,验证消息是否支付宝发过来 
        {
            if (ac_code == ac)//验证消息是否被修改
            {
                //数据库操作
            }
        }
    }
    if (action == "checkout")  //交易完成通知 
    {
        returntxt = "n";
        if (responsetxt.substring(0, 4) == "true"
            || responsetxt.substring(0, 4) == "fals")//atn,验证消息是否支付宝发过来 
        {
            if (ac_code == ac)//验证消息是否被修改
            {
                //数据库操作    
            }
        }
    }
    system.web.httpcontext.current.response.write(returntxt);
}
script>
说明:网上赠与服务集成技术文档v1.35.pdf
阅读(619) | 评论(0) | 转发(0) |
0

上一篇:没有了

下一篇:没有了

给主人留下些什么吧!~~
")); function link(t){ var href= $(t).attr('href'); href ="?url=" encodeuricomponent(location.href); $(t).attr('href',href); //setcookie("returnouturl", location.href, 60, "/"); }
网站地图