吐槽:沙箱模式看似为测试支付提供了便利,实则为鸡肋,沙箱模式获取的是开发者的信息,而沙箱需要使用特定账号,需使用pc接口去获得沙箱所需个人支付信息,PC需验证、授权、拼接、换取等一系列操作才能拿到测试的用户信息,由于过程过于复杂,未亲测。PS:或许有更好的办法,请原谅我是一个小丑。
唤起支付,原生请使用my.tradePay(前端)
uni.requestPayment({ //多端uniapp项目
provider:'alipay',
orderInfo:result.data.order_id,
success:(res)=>{
console.log(res)
},
fail:(res)=>{
console.log(res)
}
})
my.tradePay({ //支付宝原生唤起支付
tradeNO: '201711152100110410533667792',
success: (res) => {
my.alert({
content: JSON.stringify(res),
});
},
fail: (res) => {
my.alert({
content: JSON.stringify(res),
});
}
});
PHP创建订单(后端)
use app\api\controller\aop\AopClient;
use app\api\controller\aop\AopEncrypt;
use app\api\controller\aop\EncryptParseItem;
use app\api\controller\aop\EncryptResponseData;
use app\api\controller\aop\SignData;
use app\api\controller\aop\request\AlipaySystemOauthTokenRequest;
//以上引入支付宝官方SDK
$aop = new AopClient ();
$aop->appId = Config::get('appId'); // APPID
$aop->rsaPrivateKey = Config::get('rsaPrivateKey'); // 生成的RSA私钥
$aop->alipayrsaPublicKey = Config::get('alipayrsaPublicKey'); // 生成的RSA公钥
$aop->signType= "RSA2";
$aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
$aop->apiVersion = '1.0';
$aop->postCharset='UTF-8';
$aop->format='json';
// $user = Db::name('user')->where(['user_id'=>$order_data['user_id']])->find();
$object = new \stdClass();
$object->out_trade_no = $order_data['order_no'];
$object->total_amount = $order_data['total_price'];
$object->subject = $params['title'];
$object->buyer_id = $this->user['open_id'];
$object->timeout_express = '10m';
$json = json_encode($object);
$zidingyi = new AlipayTradeCreateRequest();
$zidingyi->setNotifyUrl('');
$zidingyi->setBizContent($json);
$result = $aop->execute($zidingyi);
$responseNode = str_replace(".", "_", $zidingyi->getApiMethodName()) . "_response";
$resultCode = $result->$responseNode->code;
// dump($result);
if(!empty($resultCode)&&$resultCode == 10000){
return $this->renderSuccess(['order_id' => $order_data['order_no'],'responseNode'=>$responseNode]);
} else {
return $this->renderError('统一收单失败');
}
php支付订单(后端)
待续...