首页 > 学院 > 开发设计 > 正文

支付宝网页支付

2019-11-09 18:41:04
字体:
来源:转载
供稿:网友
1.填写配置信息function alipayConfig() { //合作身份者id,以2088开头的16位纯数字 $alipay_config ['partner'] = ''; //收款支付宝账号,一般情况下收款账号就是签约账号 $alipay_config ['seller_email'] = ''; //安全检验码,以数字和字母组成的32位字符 $alipay_config ['key'] = '; //签名方式 不需修改 $alipay_config ['sign_type'] = strtoupper ( 'md5' ); //字符编码格式 目前支持 gbk 或 utf-8 $alipay_config ['input_charset'] = strtolower ( 'utf-8' ); //ca证书路径地址,用于curl中ssl校验 //请保证cacert.pem文件在当前文件夹目录中 //$alipay_config['cacert'] = getcwd().'//cacert.pem'; //访问模式,根据自己的服务器是否支持ssl访问,若支持请选择https;若不支持请选择http $alipay_config ['transport'] = 'http'; return $alipay_config; }

2.支付请求连接

 function alipayapi() { $alipay_config = $this->alipayConfig (); $payment_type = "1"; //支付类型//必填,不能修改 //http://shop/index.php?m=&c=index&a=index# $notify_url = "http://notify_url"; //服务器异步通知页面路径//需http://格式的完整路径,不能加?id=123这类自定义参数 $return_url = "http://return_url"; //页面跳转同步通知页面路径//需http://格式的完整路径,不能加?id=123这类自定义参数,不能写成http://localhost/ $oid = $_GET ['oid']; $out_trade_no = "lsd" . time () . "_" . $_GET ['oid']; //商户网站订单系统中唯一订单号,必填 $funcLog = M ( "appdb.app_elife_order" )->where ( "id=$oid" )->find (); $mname = $funcLog ['item_name']; $subject = "购买功能({$mname})付费"; //订单名称,必填 if (! $funcLog) exit (); $total_fee = round ( $funcLog ['sale_amount'], 2 ); //付款金额,必填 $body = $_GET ['desc'] ? $_GET ['desc'] : ''; //订单描述(暂无) $show_url = $_GET ['url'] ? $_GET ['url'] : ''; //商品展示地址(暂无)//需以http://开头的完整路径,例如:http://www.商户网址.com/myorder.html $anti_phishing_key = ""; //防钓鱼时间戳//若要使用请调用类文件submit中的query_timestamp函数 $exter_invoke_ip = ""; //客户端的IP地址//非局域网的外网IP地址,如:221.0.0.1 //构造要请求的参数数组,无需改动 //dump($funcLog);die(); $parameter = array ("service" => "create_direct_pay_by_user", "partner" => trim ( $alipay_config ['partner'] ), "seller_email" => trim ( $alipay_config ['seller_email'] ), "payment_type" => $payment_type, "notify_url" => $notify_url, "return_url" => $return_url, "out_trade_no" => $out_trade_no, "subject" => $subject, "total_fee" => $total_fee, "body" => $body, "show_url" => $show_url, "anti_phishing_key" => $anti_phishing_key, "exter_invoke_ip" => $exter_invoke_ip, "_input_charset" => trim ( strtolower ( $alipay_config ['input_charset'] ) ) ); //建立请求 $alipaySubmit = new AlipaySubmit ( $alipay_config ); $html_text = $alipaySubmit->buildRequestForm ( $parameter, "post", "" ); echo $html_text; }3.异步通知

function notify_url() { $alipay_config = $this->alipayConfig (); $alipayNotify = new AlipayNotify ( $alipay_config ); $verify_result = $alipayNotify->verifyNotify (); $data = array (); $data ['oid'] = substr ( strstr ( $_POST ['out_trade_no'], "_" ), 1 ); $data ['trade_no'] = $_POST ['trade_no']; $data ['gmt_time'] = $_POST ['gmt_create']; $data ['total_fee'] = $_POST ['total_fee']; $data ['seller_email'] = $_POST ['seller_email']; $data ['buyer_email'] = $_POST ['buyer_email']; $data ['trade_status'] = $_POST ['trade_status']; $data ['type'] = 1; M ( 'appdb.app_elife_paylog' )->add ( $data ); if ($verify_result) { //验证成功 $out_trade_no = $_POST ['out_trade_no']; //商户订单号 $trade_no = $_POST ['trade_no']; //支付宝交易号 $out_trade_no = substr ( strstr ( $out_trade_no, "_" ), 1 ); $trade_status = $_POST ['trade_status']; //交易状态 $total_fee = $_POST ['total_fee']; //交易金额 $buyer_email = $_POST ['buyer_email']; //买家支付宝账号 if ($_POST ['trade_status'] == 'TRADE_FINISHED') { //处理订单逻辑操作 } else if ($_POST ['trade_status'] == 'TRADE_SUCCESS') { //处理订单逻辑操作 } echo "success"; //请不要修改或删除 } else { //验证失败 echo "fail"; //调试用,写文本函数记录程序运行情况是否正常 } }4.同步操作页面

function return_url() { $alipay_config = $this->alipayConfig (); $alipayNotify = new AlipayNotify ( $alipay_config ); $verify_result = $alipayNotify->verifyReturn (); $code = 1; $out_trade_no = $_GET ['out_trade_no']; //商户订单号 $out_trade_no = substr ( strstr ( $out_trade_no, "_" ), 1 ); $trade_no = $_GET ['trade_no']; //支付宝交易号 $data = array (); $data ['oid'] = substr ( strstr ( $_GET ['out_trade_no'], "_" ), 1 ); $data ['trade_no'] = $_GET ['trade_no']; $data ['gmt_time'] = $_GET ['gmt_create']; $data ['total_fee'] = $_GET ['total_fee']; $data ['seller_email'] = $_GET ['seller_email']; $data ['buyer_email'] = $_GET ['buyer_email']; $data ['trade_status'] = $_GET ['trade_status']; $data ['type'] = 1; M ( 'appdb.app_elife_paylog' )->add ( $data ); if ($verify_result) { //验证成功 $trade_status = $_GET ['trade_status']; //交易状态 $total_fee = $_GET ['total_fee']; //交易金额 $buyer_email = $_GET ['buyer_email']; //买家支付宝账号 logResult ( $out_trade_no . " 交易成功_2 " . $trade_no ); if ($_GET ['trade_status'] == 'TRADE_FINISHED' || $_GET ['trade_status'] == 'TRADE_SUCCESS') { $this->changeFuncOrderStatus ( $out_trade_no, 2, $trade_no, $total_fee ); } else { $code = 2; echo "trade_status=" . $_GET ['trade_status']; } } else { $code = 2; logResult ( $out_trade_no . " 交易失败_2 " . $trade_no ); } $this->assign ( "code", $code ); $this->display (); }


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表