Authored by 郝肖肖

单击已完成支付 发送一次支付确认接口

@@ -6,6 +6,8 @@ use WebPlugin\Pay\PayAbstract; @@ -6,6 +6,8 @@ use WebPlugin\Pay\PayAbstract;
6 use WebPlugin\Pay\Reqparams; 6 use WebPlugin\Pay\Reqparams;
7 use WebPlugin\Pay\Rspparams; 7 use WebPlugin\Pay\Rspparams;
8 use WebPlugin\PhpLog; 8 use WebPlugin\PhpLog;
  9 +use WebPlugin\Helpers;
  10 +use Api\Yohobuy;
9 11
10 class Service extends PayAbstract 12 class Service extends PayAbstract
11 { 13 {
@@ -77,7 +79,6 @@ class Service extends PayAbstract @@ -77,7 +79,6 @@ class Service extends PayAbstract
77 79
78 public function getPayRequestPars(Reqparams $params) 80 public function getPayRequestPars(Reqparams $params)
79 { 81 {
80 - $front_notify_url = SDK_FRONT_NOTIFY_URL . '?order_code=' . $params->orderCode;  
81 $requestParams = array( 82 $requestParams = array(
82 'version' => '5.0.0', //版本号 83 'version' => '5.0.0', //版本号
83 'encoding' => 'utf-8', //编码方式 84 'encoding' => 'utf-8', //编码方式
@@ -85,8 +86,8 @@ class Service extends PayAbstract @@ -85,8 +86,8 @@ class Service extends PayAbstract
85 'txnType' => '01', //交易类型 86 'txnType' => '01', //交易类型
86 'txnSubType' => '01', //交易子类 87 'txnSubType' => '01', //交易子类
87 'bizType' => '000201', //业务类型 88 'bizType' => '000201', //业务类型
88 - 'frontUrl' => $front_notify_url, //前台通知地址  
89 - 'backUrl' => SDK_BACK_NOTIFY_URL, //后台通知地址 89 + 'frontUrl' => Helpers::url('/pay/payreturn/unionpaywebreturn', array('order_code' => $params->orderCode)), //前台通知地址--同步地址
  90 + 'backUrl' => Yohobuy::SERVICE_URL . '/payment/unionpay_newnotify',//后台通知地址--异步地址
90 'signMethod' => '01', //签名方法 91 'signMethod' => '01', //签名方法
91 'channelType' => '07', //渠道类型,07-PC,08-手机 92 'channelType' => '07', //渠道类型,07-PC,08-手机
92 'accessType' => '0', //接入类型 93 'accessType' => '0', //接入类型
  1 +<?php
  2 +
  3 +namespace WebPlugin;
  4 +/**
  5 + * 发送短信
  6 + */
  7 +class SendSms
  8 +{
  9 + private static $url = 'http://www.ztsms.cn/sendSms.do';
  10 + private static $username = 'youhuo';
  11 + private static $password = '22b5d8454c5cea4d972b1b4958227d8f';
  12 + private static $productid = '333333';
  13 +
  14 + protected static $code = array(
  15 + '-1' => '用户名或者密码不正确或用户禁用或者是管理账户',
  16 + '1' => '发送短信成功',
  17 + '0' => '发送短信失败',
  18 + '2' => '余额不够或扣费错误',
  19 + '3' => '扣费失败异常',
  20 + '5' => '短信定时成功',
  21 + '6' => '有效号码为空',
  22 + '7' => '短信内容为空',
  23 + '8' => '无签名,必须,格式:【签名】',
  24 + '9' => '没有Url提交权限',
  25 + '10' => '发送号码过多,最多支持2000个号码',
  26 + '11' => '产品ID异常或产品禁用',
  27 + '12' => '参数异常',
  28 + '15' => 'Ip验证失败',
  29 + '19' => '短信内容过长,最多支持500个,或提交编码异常导致',
  30 + );
  31 + /**
  32 + * 发送普通短信
  33 + * @param type array $mobiles 手机号
  34 + * @param type string $content 内容
  35 + * @return type []
  36 + */
  37 + public static function ordinarySms($mobiles, $content)
  38 + {
  39 + if (empty($mobiles)) {
  40 + return self::$code[6];
  41 + }
  42 +
  43 + if (empty($content)) {
  44 + return self::$code[7];
  45 + }
  46 +
  47 + if (is_string($mobiles)) {
  48 + $mobiles = array($mobiles);
  49 + }
  50 +
  51 + $mobiles = array_unique($mobiles);
  52 +
  53 + $data = array(
  54 + 'mobile' => implode(',', $mobiles),
  55 + 'content' => $content
  56 + );
  57 +
  58 + $result = self::post($data);
  59 +
  60 + if (isset($result[0]) && $result[0] * 1 === 1) {
  61 + return array('code' => 200, 'msg' => self::$code[$result[0]]);
  62 + }
  63 +
  64 + return array('code' => 400, 'msg' => isset(self::$code[$result[0]]) ? self::$code[$result[0]] : '发送失败');
  65 + }
  66 +
  67 + private static function post($data = array(), $timeout = 50)
  68 + {
  69 + $ch = curl_init(self::$url);
  70 + $data['username'] = self::$username;
  71 + $data['password'] = self::$password;
  72 + $data['productid'] = self::$productid;
  73 + $data['content'] = $data['content'];
  74 +
  75 + curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
  76 + curl_setopt($ch, CURLOPT_HEADER, 0);
  77 + curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.122 YOHOWEB');
  78 + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  79 + curl_setopt($ch, CURLOPT_POST, true);
  80 +
  81 + if (!empty($data)) {
  82 + curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data, null, '&'));
  83 + }
  84 +
  85 + $result = curl_exec($ch);
  86 +
  87 + if (!empty($result)) {
  88 + $result = explode(',', $result);
  89 + }
  90 +
  91 + curl_close($ch);
  92 + unset($ch, $data);
  93 +
  94 + return $result;
  95 + }
  96 +}
@@ -71,7 +71,7 @@ @@ -71,7 +71,7 @@
71 <p>完成付款后请根据您的情况点击下面的按钮</p> 71 <p>完成付款后请根据您的情况点击下面的按钮</p>
72 </div> 72 </div>
73 <div class="btns"> 73 <div class="btns">
74 - <a href="{{ordersUrl}}" class="over">已完成付款</a> 74 + <a href="javascript:void(0);" data-url = "{{ordersUrl}}"class="pay-over over">已完成付款</a>
75 <a href="#" class="change">更换支付方式</a> 75 <a href="#" class="change">更换支付方式</a>
76 </div> 76 </div>
77 <a href="#" class="close">x</a> 77 <a href="#" class="close">x</a>
@@ -18,7 +18,8 @@ var $ = require('yoho.jquery'), @@ -18,7 +18,8 @@ var $ = require('yoho.jquery'),
18 showDiv, 18 showDiv,
19 imgAlt, 19 imgAlt,
20 imgSrc, 20 imgSrc,
21 - orderCode; 21 + orderCode,
  22 + payment;
22 23
23 $.jqtab = function(tabtit, tabcon) { 24 $.jqtab = function(tabtit, tabcon) {
24 25
@@ -77,24 +78,37 @@ $('.change').click(function() { @@ -77,24 +78,37 @@ $('.change').click(function() {
77 }); 78 });
78 79
79 //支付方式选择按钮 80 //支付方式选择按钮
80 -function getData(payment,orderCode){  
81 - $.ajax({  
82 - type:"get",  
83 - url:"/common/addpaymentinterval",  
84 - dataType:'json',  
85 - data:{  
86 - orderCode:orderCode,  
87 - payment:payment  
88 - }  
89 -  
90 - }); 81 +function getData(payment, orderCode) {
  82 + $.ajax({
  83 + type: 'get',
  84 + url: '/common/addpaymentinterval',
  85 + dataType: 'json',
  86 + data: {
  87 + orderCode: orderCode,
  88 + payment: payment
  89 + }
  90 + });
91 } 91 }
92 92
93 -$("#btnby").click(function(){  
94 - payment = $(".choose-type").attr("data-id");  
95 - orderCode = $('.order-num').text();  
96 - getData(payment,orderCode); 93 +$('#btnby').click(function() {
  94 + payment = $('.choose-type').attr('data-id');
  95 + orderCode = $('.order-num').text();
  96 + getData(payment, orderCode);
97 window.open($payUrl + '?order_code=' + orderCode + '&payment_type=' + $showValue); 97 window.open($payUrl + '?order_code=' + orderCode + '&payment_type=' + $showValue);
98 $lightBox.show(); 98 $lightBox.show();
99 -}) 99 +});
100 100
  101 +//发送支付确认
  102 +$('.pay-over').unbind('click').bind('click', function() {
  103 + var _this = this;
  104 +
  105 + $.post('/shopping/pay/sendPay',
  106 + {
  107 + orderCode: orderCode,
  108 + paymentId: payment
  109 + },
  110 + function() {
  111 + window.location.href = $(_this).data('url');
  112 + }
  113 + );
  114 +});
@@ -409,26 +409,25 @@ class PaymentModel @@ -409,26 +409,25 @@ class PaymentModel
409 return $uid; 409 return $uid;
410 } 410 }
411 /** 411 /**
412 - * 支付成功后--确认接口  
413 - * @param type object $payResult 订单号 412 + * 支付成功后--发送支付确认接口
  413 + * @param type object $orderCode 订单号
414 * @param type int $paymentId 支付方式id 414 * @param type int $paymentId 支付方式id
415 * @param type int $uid 用户ID 415 * @param type int $uid 用户ID
416 * @return type [] 416 * @return type []
417 */ 417 */
418 - public static function payConfirm($payResult, $paymentId, $uid) 418 + public static function sendPayConfirm($orderCode, $paymentId, $uid)
419 { 419 {
420 -// UdpLog::info("【支付成功-发送确认接口】,function:payConfirm,支付方式ID:{$paymentId},参数", $payResult);  
421 - if (empty($payResult->orderCode)) { 420 +// UdpLog::info("【支付成功-发送确认接口】,function:sendPayConfirm,支付方式ID:{$paymentId},参数", $payResult);
  421 + if (empty($orderCode)) {
422 return self::$code; 422 return self::$code;
423 } 423 }
424 424
425 - $orderCode = $payResult->orderCode;  
426 //如果uid,为空,则从缓存中取uid,但还是不排除uid为空的情况下。 425 //如果uid,为空,则从缓存中取uid,但还是不排除uid为空的情况下。
427 $uid = empty($uid) ? self::getUid($orderCode) : $uid; 426 $uid = empty($uid) ? self::getUid($orderCode) : $uid;
428 $confirm = PayData::payConfirm($orderCode, $paymentId, $uid); 427 $confirm = PayData::payConfirm($orderCode, $paymentId, $uid);
429 428
430 // UdpLog::info( 429 // UdpLog::info(
431 -// "【支付成功-发送确认接口】,function:payConfirm,orderCode:{$orderCode},支付方式ID:{$paymentId},接口返回", 430 +// "【支付成功-发送确认接口】,function:sendPayConfirm,orderCode:{$orderCode},支付方式ID:{$paymentId},接口返回",
432 // array('confirm' => $confirm, '$payResult' => $payResult) 431 // array('confirm' => $confirm, '$payResult' => $payResult)
433 // ); 432 // );
434 return $confirm; 433 return $confirm;
@@ -63,6 +63,18 @@ class PayreturnController extends WebAction @@ -63,6 +63,18 @@ class PayreturnController extends WebAction
63 $this->commonShowResult($dealResult); 63 $this->commonShowResult($dealResult);
64 } 64 }
65 /** 65 /**
  66 + * 银联web支付返回
  67 + */
  68 + public function unionpaywebreturnAction()
  69 + {
  70 + $payment = PayModel::getPaymentById(25);
  71 + $payService = PayFactory::factory($payment);
  72 + $res = $payService->parseResponse($_REQUEST);
  73 + $dealResult = $this->payResultProc($res, 25);
  74 + $dealResult['payData'] = array('payWay' => '银联在线支付');
  75 + $this->commonShowResult($dealResult);
  76 + }
  77 + /**
66 * 通用显示结果的方法 78 * 通用显示结果的方法
67 * @param array $dealResult 79 * @param array $dealResult
68 */ 80 */
@@ -100,9 +112,11 @@ class PayreturnController extends WebAction @@ -100,9 +112,11 @@ class PayreturnController extends WebAction
100 ); 112 );
101 113
102 if ($payResult->payResult == 200) { 114 if ($payResult->payResult == 200) {
103 - //支付成功,发送一次支付确认  
104 - $uid = $this->getUid(true);  
105 - PaymentModel::payConfirm($payResult, $payment, $uid); 115 + if (!empty($payResult->orderCode)) {
  116 + //支付成功,发送一次支付确认
  117 + $uid = $this->getUid(true);
  118 + PaymentModel::sendPayConfirm($payResult, $payment, $uid);
  119 + }
106 120
107 //支付成功 121 //支付成功
108 $result = PaymentModel::procOrderData($payResult, $payment); 122 $result = PaymentModel::procOrderData($payResult, $payment);
@@ -71,7 +71,25 @@ class PayController extends WebAction @@ -71,7 +71,25 @@ class PayController extends WebAction
71 'payPage' => true 71 'payPage' => true
72 )); 72 ));
73 } 73 }
74 - 74 + /**
  75 + * 单击已完成支付按钮--发送一次支付确认
  76 + */
  77 + public function sendPayAction()
  78 + {
  79 + $result = array('code' => 400, 'message' => '操作失败!');
  80 + if ($this->isAjax()) {
  81 + do {
  82 + $uid = $this->getUid(true);
  83 + $orderCode = $this->post('orderCode', 0);
  84 + $paymentId = $this->post('paymentId', 0);
  85 + if (empty($orderCode) || empty($uid) || empty($paymentId)) {
  86 + break;
  87 + }
  88 + $result = PaymentModel::sendPayConfirm($orderCode, $paymentId, $uid);
  89 + } while (false);
  90 + }
  91 + $this->echoJson($result);
  92 + }
75 } 93 }
76 94
77 95