tp3.2 支付宝app支付
Posted 如果巴黎不快乐……
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了tp3.2 支付宝app支付相关的知识,希望对你有一定的参考价值。
pay方法
1 /** 2 *支付宝支付 3 */ 4 public function pay($param) { 5 vendor(‘alipay.AopSdk‘);// 加载类库 6 $config = array( 7 ‘appid‘ =>‘2018032002414339‘,//商户密钥 8 ‘rsaPrivateKey‘ =>‘MIIEpQIBAAKCAQEAyvY7nagGZke/TE1Vj+/6WiePz2E02soBv4V8rzwSWz8NXZem1cqcueILPSgDBbB5OqUa+um9iUeqhOzjItdMFWD3ItVXLLVcTdX/PIaeZO3CBfyKEHIwwMLasJOb7P8ctmCPJVwbxQuXdeKaoJT/MAZY/pLNqUwRTp7AFb0VW5t71Tm7vLHrDkvQBL9f2hlUAt7GMJPPLOV3EZ2jWmBQk4dNxK+72D1+0DQq3D3smk93BOl4STaIxddLrSz13rvzON/SFGi+IBlHRtErrBcVeVyJ/nVvdWSFo4DWkXmlNKzyJmXKa6HhMrtYs1RjeLX0TBAtgAJVKJc4fbw65L9xowIDAQABAoIBAQCTTeT0xrdmUlpf+ZzI6+Yqup3gaG+g/44HP82/rPyxpvB/ZgqbDgNz0cBQcZLH9U33J0+OnkiGszHqabdsWRAKUCbt7CLp+vL0NwWZGycon3r7N0/JIeeKb6GjGG7JslpXb3tVJSWufHw//eg19g3EAEdk9I05e1DwW72TyXkP010JpNz8zQhzUrGBh4IFNxyUD13sSBgTPpcrHIr7Ch85Mh3Wi9erik9iv+T1mkPluil6WgarwD0Gc2RdGr8rB3ml6NdAhDI5bVB9uZ6DD9ui67EfgomjJeoA172z3J5SZtsqApxc9VW7Y4EOG9HNdciOZk7gRe6H+6GJrmAfFXthAoGBAO0godHlBi9MsihnpzntviNGFV2cf3ZUAKyFjCdtfHHFlOSgq59oJ80x6Rcjh2ZytiZyQwN2XAU3w7jKpKfi4/UbXu0ZTxs5ptSxn+iyXS/sMGgX00WdOqRXkM+gqU2zM5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zON/SFGi+IBlHRtErrBcVeVyJ/nVvdWSFo4DWkXmlNKzyJmXKa6HhMrtYs1RjeLX0TBAtgAJVKJc4fbw65L9xowIDAQAB‘,//公钥 10 ‘charset‘=>strtolower(‘utf-8‘),//编码 11 ‘notify_url‘ =>‘http://60.205.111.111:8087/jiceng/Notifyurl/index‘,//回调地址(支付宝支付成功后回调修改订单状态的地址) 12 ‘payment_type‘ =>1,//(固定值) 13 ‘seller_id‘ =>‘2088031565381518‘,//收款商家账号5abd9e4d92fef 14 ‘charset‘ => ‘utf-8‘,//编码 15 ‘sign_type‘ => ‘RSA2‘,//签名方式 16 ‘timestamp‘ =>date("Y-m-d H:i:s"), 17 ‘version‘ =>"1.0",//固定值 18 ‘url‘ => ‘https://openapi.alipay.com/gateway.do‘,//固定值 19 ‘method‘ => ‘alipay.trade.app.pay‘,//固定值 20 ); 21 //构造业务请求参数的集合(订单信息) 22 $order=date("YmdHis").time().mt_rand(1000,9999);//订单号 23 $price=$param[‘price‘];//价格 24 $uid=$param[‘userid‘];//用户编号 25 Response::debug($price.‘+‘.$uid); 26 //添加账单 27 $obj = array( 28 "userid" => $uid, 29 "charge" =>$price, 30 ‘paytime‘=>time(), 31 "paytype"=>‘支付宝‘, 32 "paystate"=>0, 33 "order"=>$order 34 ); 35 $insert=M(‘api_charge‘)->add($obj); 36 $content = array(); 37 $content[‘body‘] = ‘‘; 38 $content[‘subject‘] = ‘充值‘;//商品的标题/交易标题/订单标题/订单关键字等 39 $content[‘out_trade_no‘] = $order;//商户网站唯一订单号 40 $content[‘timeout_express‘] = ‘1d‘;//该笔订单允许的最晚付款时间 41 $content[‘total_amount‘] = floatval($price);//订单总金额(必须定义成浮点型) 42 $content[‘seller_id‘] = $config[‘seller_id‘];//收款人账号 43 $content[‘product_code‘] = ‘QUICK_MSECURITY_PAY‘;//销售产品码,商家和支付宝签约的产品码,为固定值QUICK_MSECURITY_PAY 44 $content[‘store_id‘] = ‘001‘;//商户门店编号 45 $con = json_encode($content);//$content是biz_content的值,将之转化成字符串 46 //公共参数 47 $param = array(); 48 $Client = new \AopClient();//实例化支付宝sdk里面的AopClient类,下单时需要的操作,都在这个类里面 49 $param[‘app_id‘] = $config[‘appid‘];//支付宝分配给开发者的应用ID 50 $param[‘method‘] = $config[‘method‘];//接口名称 51 $param[‘charset‘] = $config[‘charset‘];//请求使用的编码格式 52 $param[‘sign_type‘] = $config[‘sign_type‘];//商户生成签名字符串所使用的签名算法类型 53 $param[‘timestamp‘] = $config[‘timestamp‘];//发送请求的时间 54 $param[‘version‘] = $config[‘version‘];//调用的接口版本,固定为:1.0 55 $param[‘notify_url‘] = $config[‘notify_url‘];//支付宝服务器主动通知地址 56 $param[‘biz_content‘] = $con;//业务请求参数的集合,长度不限,json格式 57 58 //生成签名 59 60 $paramStr = $Client->getSignContent($param); 61 $sign = $Client->alonersaSign($paramStr,$config[‘rsaPrivateKey‘],‘RSA2‘); 62 $param[‘sign‘] = $sign; 63 $str = $Client->getSignContentUrlencode($param); 64 65 66 67 return array(‘url‘=>$str); 68 }
异步回调
1 /** 2 *支付宝支付回调 3 */ 4 public function index() 5 { 6 7 vendor(‘alipay.AopSdk‘);// 加载类库 8 $aop = new \AopClient; 9 $aop->alipayrsaPublicKey = ‘MIIBIjANBgkqhkiG99M6YvyBq/RlnZpWYUmIXFGKjUEgX7VkttbDgWB0q3hyPQydJED4WkcVx96FXYq/RALIbJ21+fd35ibBaeUsKQcKxEwBUK2Bs2bwR/G3x4T19yTLkELU0Zgi4eUe/+6ELu/wQEet7Aj5DrI1pbtSKi64LZDxoXAHePK3CtzFcDoNcCE1FH0C5GvyQO5oYna2VSZFX55wDw559EMpHXxRGPs8TR9VRqCuxWMZrBt/tYj57zOU81i3U9IwvijwxuVo45kr4fN/3MU5qEUEQwRcdtAuIHsfJ0dR1bOOk8OeWZ9pg/da/oR6iUUAkzQIDAQAB‘; 10 $flag = $aop->rsaCheckV1($_POST, NULL, "RSA2"); 11 if ($flag) { 12 if ($_POST[‘trade_status‘] == ‘TRADE_FINISHED‘ || $_POST[‘trade_status‘] == ‘TRADE_SUCCESS‘) 13 { 14 $out_trade_no = $_POST[‘out_trade_no‘]; //商户订单号 15 $data[‘paystate‘]=1; 16 $res = D(‘api_charge‘)->where(array(‘order‘ => $out_trade_no))->save($data); 17 if( $res === false ){ 18 echo ‘fail‘; 19 }else{ 20 echo ‘success‘; 21 } 22 23 } 24 } 25 26 27 }
以上是关于tp3.2 支付宝app支付的主要内容,如果未能解决你的问题,请参考以下文章