<h2 style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: "Helvetica Neue", NotoSansHans-Regular, AvenirNext-Regular, arial, "Hiragino Sans GB", "Microsoft Yahei", "WenQuanYi Micro Hei", Arial, Helvetica, sans-serif; padding: 0px 0px 0.3em; font-weight: 400; line-height: 1.225; margin: 0px 0px 14px; font-size: 1.3em; border-bottom: 1px solid rgb(238, 238, 238); color: rgb(82, 82, 82); white-space: normal; background-color: rgb(255, 255, 255);">
<span style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-weight: bolder;">支付寶Oauth配置</span>
</h2>
<p style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; line-height: 2; margin-top: 0px; margin-bottom: 0px; padding: 0px; color: rgb(82, 82, 82); font-family: "Helvetica Neue", NotoSansHans-Regular, AvenirNext-Regular, arial, "Hiragino Sans GB", "Microsoft Yahei", "WenQuanYi Micro Hei", serif; font-size: 15px; white-space: normal; background-color: rgb(255, 255, 255);">
系統默認寫好了Oauth方法 舊方法簽名使用的RSA 但是現在新申請的應用簽名使用RSA2
</p>
<p style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; line-height: 2; margin-top: 0px; margin-bottom: 0px; padding: 0px; color: rgb(82, 82, 82); font-family: "Helvetica Neue", NotoSansHans-Regular, AvenirNext-Regular, arial, "Hiragino Sans GB", "Microsoft Yahei", "WenQuanYi Micro Hei", serif; font-size: 15px; white-space: normal; background-color: rgb(255, 255, 255);">
<img src="https://box.kancloud.cn/579366df1a37cb3cc1cc8f0d2c62ded8_718x398.png" alt=""/>
</p>
<p style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; line-height: 2; margin-top: 0px; margin-bottom: 0px; padding: 0px; color: rgb(82, 82, 82); font-family: "Helvetica Neue", NotoSansHans-Regular, AvenirNext-Regular, arial, "Hiragino Sans GB", "Microsoft Yahei", "WenQuanYi Micro Hei", serif; font-size: 15px; white-space: normal; background-color: rgb(255, 255, 255);">
<span style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-weight: bolder;">如上圖 如申請的應用有使用其他加密方式參數時可以使用默認的RSA簽名(代碼無需改動 使用下面的默認的公鑰配置下就可以) 如沒有則使用RSA2(修改代碼 參考下面代碼修改)</span>
</p>
<h3 style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: "Helvetica Neue", NotoSansHans-Regular, AvenirNext-Regular, arial, "Hiragino Sans GB", "Microsoft Yahei", "WenQuanYi Micro Hei", Arial, Helvetica, sans-serif; padding: 0px; font-weight: 400; line-height: 1.43; margin: 14px 0px; font-size: 1.2em; color: rgb(82, 82, 82); white-space: normal; background-color: rgb(255, 255, 255);">
<a style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; background-color: transparent; color: rgb(65, 131, 196); margin-top: -10px; position: absolute;"></a>申請應用步驟:
</h3>
<p style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; line-height: 2; margin-top: 0px; margin-bottom: 0px; padding: 0px; color: rgb(82, 82, 82); font-family: "Helvetica Neue", NotoSansHans-Regular, AvenirNext-Regular, arial, "Hiragino Sans GB", "Microsoft Yahei", "WenQuanYi Micro Hei", serif; font-size: 15px; white-space: normal; background-color: rgb(255, 255, 255);">
1.(企業或個人賬戶)登錄https://open.alipay.com<br/>2.進入管理中心-頭部菜單-開發者中心-網頁&移動應用接入---創建應用選擇-自定義接入-設置應用名稱-創建<br/>3.創建完成后再功能列表添加功能-第三方應用授權-確定添加<br/>4.開發設置-加密方式處設置應用公鑰(利用支付寶提供的生成工具生成就可以了,將生成的參數保存到公鑰處)<br/>簽名工具下載: <a href="https://docs.open.alipay.com/291/106097" target="_blank" style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; background-color: transparent; color: rgb(65, 131, 196); text-decoration-line: none;">https://docs.open.alipay.com/291/106097</a>
</p>
<h3 style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: "Helvetica Neue", NotoSansHans-Regular, AvenirNext-Regular, arial, "Hiragino Sans GB", "Microsoft Yahei", "WenQuanYi Micro Hei", Arial, Helvetica, sans-serif; padding: 0px; font-weight: 400; line-height: 1.43; margin: 14px 0px; font-size: 1.2em; color: rgb(82, 82, 82); white-space: normal; background-color: rgb(255, 255, 255);">
<a style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; background-color: transparent; color: rgb(65, 131, 196); margin-top: -10px; position: absolute;"></a>系統配置
</h3>
<p style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; line-height: 2; margin-top: 0px; margin-bottom: 0px; padding: 0px; color: rgb(82, 82, 82); font-family: "Helvetica Neue", NotoSansHans-Regular, AvenirNext-Regular, arial, "Hiragino Sans GB", "Microsoft Yahei", "WenQuanYi Micro Hei", serif; font-size: 15px; white-space: normal; background-color: rgb(255, 255, 255);">
品牌商總后臺-系統配置-支付配置-支付寶Appid配置為上述申請應用后的Appid<br/>開發文件修改:<br/>根目錄/ThinkPHP/Library/Vendor/alipay_sdk/AlipayAop.php<br/>方法為Alipay_oauth
</p>
<p style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; line-height: 2; margin-top: 0px; margin-bottom: 0px; padding: 0px; color: rgb(82, 82, 82); font-family: "Helvetica Neue", NotoSansHans-Regular, AvenirNext-Regular, arial, "Hiragino Sans GB", "Microsoft Yahei", "WenQuanYi Micro Hei", serif; font-size: 15px; white-space: normal; background-color: rgb(255, 255, 255);">
<span style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-weight: bolder;">默認代碼為:</span>
</p>
<pre style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, Monaco, "Andale Mono", "Ubuntu Mono", monospace; font-size: 15px; line-height: 1.45; margin-top: 14px; margin-bottom: 14px; padding: 16px; background-color: rgb(247, 247, 247); border: 0px; border-radius: 3px; overflow: auto; color: rgb(82, 82, 82);">public function Alipay_oauth($code,$app_id){
$aop = new AopClient();
$aop->appId = $app_id;
$aop->rsaPrivateKey = 'MIICXAIBAAKBgQCbX2YDb/1k/a0pK7GlMRzMV/HoePGrcfKr/WQoKDC26p9Jv3Y+qblO5Bqke9yJ234OM+cdOIU2WZMmJ2gQuI5FjyRLWJ/Sas09t2LCaOBBT88JO4EWtYBKfISUVPwyuROFf6SseXG7Xq72S58YR6P/QZ+oDFxqoSyep1REEf8zRQIDAQABAoGAed55OOcFvcpQoYN5QtZj/VBaGfuLq+uj6g3GGs1zcHZV3NXF3N7p0ByRXUUeNi+pD2DcvgnQS1I1Xm74bG0mgeYmc0pCu+lQ6nWusUmuAJVLOH5eLn7byunTsy1sMeNcNmrc3f/dY5Ez3UPT9ZRBAbOpjTNh52+7sJljoNEoWB0CQQDIgMTePhBHXIni0aP4rsgx0J3Nwtj6XYYCr87/rUv9sF4e11bVvoiaKDfYiIPmP0mcGRFRBtGWhGBBcadkWZh/AkEAxmDJCwCw7pzU9vVaS/Y9LPmOIHbT5453p8dy+3sjO2JjU+W3tAH8VnChUVeaK9Mv+8EUjabZMQxAbKq60E/yOwJAc5Vn6AY3NCwwgMUBlZaMacstbTRqCMppOptG5TVtnS1S1MymjklsThHpP7ZS8ySAtq/sv50CrZZaNt/h84OC2QJBAMFb/zm5P7wko7PfLFdUOQbIbA8ao6tVAy5HSrzypkGwwc4535gWQ2XhvGtzrrM+0stZxHXZhmO3ZGhG9XYsJpcCQEciKjeYTISSj0ocLvOxkaiJ2OgMdS6lcGJVi124Gk+zrICagTdJgL4Ujqca79lbPebXqbRuLdANg5qmU3tMa/Y=';
$aop->alipayrsaPublicKey = 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCbX2YDb/1k/a0pK7GlMRzMV/HoePGrcfKr/WQoKDC26p9Jv3Y+qblO5Bqke9yJ234OM+cdOIU2WZMmJ2gQuI5FjyRLWJ/Sas09t2LCaOBBT88JO4EWtYBKfISUVPwyuROFf6SseXG7Xq72S58YR6P/QZ+oDFxqoSyep1REEf8zRQIDAQAB';
$aop->apiVersion = '1.0';
$aop->signType = 'RSA';
$aop->postCharset = 'UTF-8';
$aop->format = 'json';
$request = new AlipaySystemOauthTokenRequest();
$request->setGrantType("authorization_code");//設置要操作的類型
$request->setCode($code);
$response = $aop->execute($request);
$openid = $response->alipay_system_oauth_token_response->user_id;
return $openid;
}</pre>
<p style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; line-height: 2; margin-top: 0px; margin-bottom: 0px; padding: 0px; color: rgb(82, 82, 82); font-family: "Helvetica Neue", NotoSansHans-Regular, AvenirNext-Regular, arial, "Hiragino Sans GB", "Microsoft Yahei", "WenQuanYi Micro Hei", serif; font-size: 15px; white-space: normal; background-color: rgb(255, 255, 255);">
默認為RSA簽名(如應用使用RSA方式則支付寶應用公鑰設置為以下) 統一公鑰為
</p>
<pre style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, Monaco, "Andale Mono", "Ubuntu Mono", monospace; font-size: 15px; line-height: 1.45; margin-top: 14px; margin-bottom: 14px; padding: 16px; background-color: rgb(247, 247, 247); border: 0px; border-radius: 3px; overflow: auto; color: rgb(82, 82, 82);">MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCbX2YDb/1k/a0pK7GlMRzMV/HoePGrcfKr/WQoKDC26p9Jv3Y+qblO5Bqke9yJ234OM+cdOIU2WZMmJ2gQuI5FjyRLWJ/Sas09t2LCaOBBT88JO4EWtYBKfISUVPwyuROFf6SseXG7Xq72S58YR6P/QZ+oDFxqoSyep1REEf8zRQIDAQAB</pre>
<h3 style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: "Helvetica Neue", NotoSansHans-Regular, AvenirNext-Regular, arial, "Hiragino Sans GB", "Microsoft Yahei", "WenQuanYi Micro Hei", Arial, Helvetica, sans-serif; padding: 0px; font-weight: 400; line-height: 1.43; margin: 14px 0px; font-size: 1.2em; color: rgb(82, 82, 82); white-space: normal; background-color: rgb(255, 255, 255);">
<a style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; background-color: transparent; color: rgb(65, 131, 196); margin-top: -10px; position: absolute;"></a>使用RSA2方式(系統所有品牌都使用這個方式):
</h3>
<p style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; line-height: 2; margin-top: 0px; margin-bottom: 0px; padding: 0px; color: rgb(82, 82, 82); font-family: "Helvetica Neue", NotoSansHans-Regular, AvenirNext-Regular, arial, "Hiragino Sans GB", "Microsoft Yahei", "WenQuanYi Micro Hei", serif; font-size: 15px; white-space: normal; background-color: rgb(255, 255, 255);">
<img src="https://box.kancloud.cn/0a77e76a11ef650c959d4c90b6f9c04a_800x680.png" alt=""/><br/><span style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-weight: bolder;">如圖中的公鑰配置到支付寶應用中的公鑰處</span>
</p>
<p style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; line-height: 2; margin-top: 0px; margin-bottom: 0px; padding: 0px; color: rgb(82, 82, 82); font-family: "Helvetica Neue", NotoSansHans-Regular, AvenirNext-Regular, arial, "Hiragino Sans GB", "Microsoft Yahei", "WenQuanYi Micro Hei", serif; font-size: 15px; white-space: normal; background-color: rgb(255, 255, 255);">
修改方法代碼
</p>
<pre style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, Monaco, "Andale Mono", "Ubuntu Mono", monospace; font-size: 15px; line-height: 1.45; margin-top: 14px; margin-bottom: 14px; padding: 16px; background-color: rgb(247, 247, 247); border: 0px; border-radius: 3px; overflow: auto; color: rgb(82, 82, 82);">$aop->rsaPrivateKey</pre>
<p style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; line-height: 2; margin-top: 0px; margin-bottom: 0px; padding: 0px; color: rgb(82, 82, 82); font-family: "Helvetica Neue", NotoSansHans-Regular, AvenirNext-Regular, arial, "Hiragino Sans GB", "Microsoft Yahei", "WenQuanYi Micro Hei", serif; font-size: 15px; white-space: normal; background-color: rgb(255, 255, 255);">
<span style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-weight: bolder;">參數改為生成的私鑰參數</span>
</p>
<pre style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, Monaco, "Andale Mono", "Ubuntu Mono", monospace; font-size: 15px; line-height: 1.45; margin-top: 14px; margin-bottom: 14px; padding: 16px; background-color: rgb(247, 247, 247); border: 0px; border-radius: 3px; overflow: auto; color: rgb(82, 82, 82);">$aop->alipayrsaPublicKey</pre>
<p style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; line-height: 2; margin-top: 0px; margin-bottom: 0px; padding: 0px; color: rgb(82, 82, 82); font-family: "Helvetica Neue", NotoSansHans-Regular, AvenirNext-Regular, arial, "Hiragino Sans GB", "Microsoft Yahei", "WenQuanYi Micro Hei", serif; font-size: 15px; white-space: normal; background-color: rgb(255, 255, 255);">
<span style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-weight: bolder;">參數改為生成的公鑰參數</span>
</p>
<hr/>
<p style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; line-height: 2; margin-top: 0px; margin-bottom: 0px; padding: 0px; color: rgb(82, 82, 82); font-family: "Helvetica Neue", NotoSansHans-Regular, AvenirNext-Regular, arial, "Hiragino Sans GB", "Microsoft Yahei", "WenQuanYi Micro Hei", serif; font-size: 15px; white-space: normal; background-color: rgb(255, 255, 255);">
簽名方式修改
</p>
<pre style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, Monaco, "Andale Mono", "Ubuntu Mono", monospace; font-size: 15px; line-height: 1.45; margin-top: 14px; margin-bottom: 14px; padding: 16px; background-color: rgb(247, 247, 247); border: 0px; border-radius: 3px; overflow: auto; color: rgb(82, 82, 82);">$aop->signType = 'RSA';</pre>
<p style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; line-height: 2; margin-top: 0px; margin-bottom: 0px; padding: 0px; color: rgb(82, 82, 82); font-family: "Helvetica Neue", NotoSansHans-Regular, AvenirNext-Regular, arial, "Hiragino Sans GB", "Microsoft Yahei", "WenQuanYi Micro Hei", serif; font-size: 15px; white-space: normal; background-color: rgb(255, 255, 255);">
修改為:
</p>
<pre style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, Monaco, "Andale Mono", "Ubuntu Mono", monospace; font-size: 15px; line-height: 1.45; margin-top: 14px; margin-bottom: 14px; padding: 16px; background-color: rgb(247, 247, 247); border: 0px; border-radius: 3px; overflow: auto; color: rgb(82, 82, 82);">$aop->signType = 'RSA2';</pre>
<p style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; line-height: 2; margin-top: 0px; margin-bottom: 0px; padding: 0px; color: rgb(82, 82, 82); font-family: "Helvetica Neue", NotoSansHans-Regular, AvenirNext-Regular, arial, "Hiragino Sans GB", "Microsoft Yahei", "WenQuanYi Micro Hei", serif; font-size: 15px; white-space: normal; background-color: rgb(255, 255, 255);">
如果系統多個品牌 多個appid使用的有RSA RSA2 兩種方式
</p>
<p style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; line-height: 2; margin-top: 0px; margin-bottom: 0px; padding: 0px; color: rgb(82, 82, 82); font-family: "Helvetica Neue", NotoSansHans-Regular, AvenirNext-Regular, arial, "Hiragino Sans GB", "Microsoft Yahei", "WenQuanYi Micro Hei", serif; font-size: 15px; white-space: normal; background-color: rgb(255, 255, 255);">
那么需要修改代碼來進行判斷 用appid來判斷 如下面示例
</p>
<pre style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, Monaco, "Andale Mono", "Ubuntu Mono", monospace; font-size: 15px; line-height: 1.45; margin-top: 14px; margin-bottom: 14px; padding: 16px; background-color: rgb(247, 247, 247); border: 0px; border-radius: 3px; overflow: auto; color: rgb(82, 82, 82);"> public function Alipay_oauth($code,$app_id){
switch($appid){
case '2008xxxxxx':
$rsaPrivateKey='私鑰';
$alipayrsaPublicKey='公鑰';
$signType=‘RSA2’;//簽名方式;
break;
......
default:
$rsaPrivateKey='私鑰';
$alipayrsaPublicKey='公鑰';
$signType=‘RSA’;//簽名方式;
break;
}
$aop = new AopClient();
$aop->appId = $app_id;
$aop->rsaPrivateKey = $rsaPrivateKey;
$aop->alipayrsaPublicKey = $alipayrsaPublicKey;
$aop->apiVersion = '1.0';
$aop->signType = $signType;
$aop->postCharset = 'UTF-8';
$aop->format = 'json';
$request = new AlipaySystemOauthTokenRequest();
$request->setGrantType("authorization_code");//設置要操作的類型
$request->setCode($code);
$response = $aop->execute($request);
$openid = $response->alipay_system_oauth_token_response->user_id;
return $openid;
}</pre>
<p style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; line-height: 2; margin-top: 0px; margin-bottom: 0px; padding: 0px; color: rgb(82, 82, 82); font-family: "Helvetica Neue", NotoSansHans-Regular, AvenirNext-Regular, arial, "Hiragino Sans GB", "Microsoft Yahei", "WenQuanYi Micro Hei", serif; font-size: 15px; white-space: normal; background-color: rgb(255, 255, 255);">
<span style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-weight: bolder;">最重要的授權回調地址配置為自己的域名</span><br/><img src="https://box.kancloud.cn/95d7f54b82d6a0d08a447b30d07d9dea_743x447.png" alt=""/>
</p>
<p>
<br/>
</p>