The application is based on Yii. The current process is as follows:
Generate Oschina Authorization link
After the user accesses the link, they get the code
Use code in exchange for Access_token
Code:
*/class Oschinaoauth extends ccomponent{public $ak, public $sk, public $callback, private $host = ' HTTPS://WWW.OSCHINA.N ET '; Public Function init () {}/** * get authorization link * @return String */Public Function Getredirecturl () {$params = Array (' re Sponse_type ' + ' code ', ' client_id ' = $this->ak, ' Redirect_uri ' and Yii::app ()->createabsoluteurl ($th Is->callback)); Return $this->host. '/action/oauth2/authorize? '. Http_build_query ($params); }/** * Get Accesstoken * @param $code * @return String * @throws CException * @throws Exception */Public function ge Taccesstoken ($code) {$params = array (' client_id ' = = $this->ak, ' client_secret ' = = $this->sk, ' Gran T_type ' + ' authorization_code ', ' code ' = $code, ' dataType ' and ' json '); $url = $this->host. '/action/openapi/token '; $resp = Request::p ost ($url, $params); $data = Json_decode ($resp, true); return $data; } public Function Refreshaccesstoken () {}}
*/class Oauthcontroller extends controller{public function actioncallback ($code, $state) { $data = Yii::app () Oauth->getaccesstoken ($code); Print_r ($data); Public Function Actionredirect () { $url = Yii::app ()->oauth->getredirecturl (); $this->redirect ($url); }}
The current problem is that you can get code, but use code to Oschina get Access_token when the error.