好久沒更新了?使用apicloud?開發(fā)的app?接通支付寶支付
1.
先操作支付寶?需要先簽約支付寶

簽約完成審核通過后

有個(gè)公鑰設(shè)置,如果沒有就去下載,下載完?注意不要放到有中文的路徑?然后點(diǎn)擊生成

生成完復(fù)制下?放到公鑰里面?私鑰就是那個(gè)rsa_private_key.pem?

設(shè)置完后去?APIcloud?里
先配置config.xml
. <feature name="aliPay">
? ? ? <param name="urlScheme" value="AliPayA000000011" />
? </feature>
.



然后到index.html?里面
<!doctype html>
<html lang="zh-CN">
<head>
? ? <meta charset="utf-8">
<title>支付寶支付</title>
</head>
<body>
<div class="container">
<div class="panel panel-default">
<div class="panel-heading">
<strong>支付寶支付測試</strong>
</div>
<div class="panel-body">
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit"? onclick="aliPay()"class="btn btn-success">立即支付</button>
</div>
</div>
<!-- </form> -->
</div>
</div>
</div>
</body>
<script >
function aliPay() {
? var aliPay = api.require('aliPay');
aliPay.payOrder({
? ? orderInfo: '這里面是需要請求后臺接口獲取的'
? }, function(ret, err) {
? ? api.alert({
? ? ? ? title: '支付1結(jié)果',
? ? ? ? msg: ret.code,
? ? ? ? buttons: ['確定']
? ? });
});
};
</script>

都配置完了就去后臺了
后臺代碼?
建立一個(gè)index.php?的文件
public function alipay()
{
? ? ? ? require_once 'F://sapp/aop/AopClient.php';? //這倆個(gè)是支付寶提供的demo?你可以直接去支付寶上下載就像?記得更換路徑支付寶app服務(wù)端
? ? ? ? require_once 'F://sapp/aop/request/AlipayTradeAppPayRequest.php';
? ? ? ? $aop = new \AopClient();
? ? ? ? $aop->gatewayUrl = "https://openapi.alipay.com/gateway.do";
? ? ? ? $aop->appId = "appid";
? ? ? ? $aop->rsaPrivateKey = '你的私鑰';
? ? ? ? $aop->format = "json";
? ? ? ? $aop->charset = "UTF-8";
? ? ? ? $aop->signType = "RSA2";
? ? ? ? $aop->alipayrsaPublicKey = '你的公鑰匙';
//實(shí)例化具體API對應(yīng)的request類,類名稱和接口名稱對應(yīng),當(dāng)前調(diào)用接口名稱:alipay.trade.app.pay
? ? ? ? $request = new \AlipayTradeAppPayRequest();
? ? ? ? //詳細(xì)
? ? ? ? $body=$_POST['body'];
? ? //訂單信息
? ? $subject =$_POST['subject'];
? ? //訂單號
? ? $out_trade_no = $_POST['out_trade_no'];
? ? //價(jià)格
? ? $total_amount =$_POST['total_amount'];
//SDK已經(jīng)封裝掉了公共參數(shù),這里只需要傳入業(yè)務(wù)參數(shù)
? ? ? ? $bizcontent = "{\"body\":\"$body\","
? ? ? ? ? ? . "\"subject\": \"$subject\","
? ? ? ? ? ? . "\"out_trade_no\": \"$out_trade_no\","
? ? ? ? ? ? . "\"timeout_express\": \"30m\","
? ? ? ? ? ? . "\"total_amount\": \"$total_amount\","
? ? ? ? ? ? . "\"product_code\":\"QUICK_MSECURITY_PAY\""
? ? ? ? ? ? . "}";
? ? ? ? $request->setNotifyUrl("回調(diào)地址");
? ? ? ? $request->setBizContent($bizcontent);
//這里和普通的接口調(diào)用不同,使用的是sdkExecute
? ? ? ? $response = $aop->sdkExecute($request);
//htmlspecialchars是為了輸出到頁面時(shí)防止被瀏覽器將關(guān)鍵參數(shù)html轉(zhuǎn)義,實(shí)際打印到日志以及http傳輸不會(huì)有這個(gè)問題
? ? ? ? echo htmlspecialchars($response);//就是orderString 可以直接給客戶端請求,無需再做處理。
? ? }
把echo?輸出的內(nèi)容?放到前臺里面

這樣就成功了?。。?!?
AopClient.php?代碼
如有任何問題請留言