管理员
论坛积分
分
威望 点
贡献值 个
金币 枚
|
提供B2B的移动商务解决方案,通过图像识别技术,通过摄像头扫描直接查询和购买商品。
$ M/ g' |! h2 P# ?' f7 Q1.添加商品信息4 [# j$ T; a$ U5 r# x
2.添加图片* @: ~- ]+ H! w3 `
3.查询所有产品! T* A8 [5 n1 c: Z* g
4.查询某个具体产品信息" o3 }4 q+ N! [1 c' [. B- s6 p
5.删除某个产品
! Y* l; _: L4 r3 |7 R- q% j6.删除图片( g3 L! i/ G0 D( H3 a
7.图像识别
) Q* y7 e5 H# B. L/ I- m9 p0 k
& R' K9 F% h+ v, O* R. d图像识别API文档:https://www.juhe.cn/docs/api/id/117,申请后生成AppKey
& _, p$ E% l! U5 _$ y9 B
$ o4 v5 H/ k4 Q2 MPHP示例:
6 A& `9 H/ W5 D2 N$ z& |- <!--?php; m4 v& [' d+ J
- // +----------------------------------------------------------------------
8 D, F) z: b( T+ o1 i# s - // | JuhePHP [ NO ZUO NO DIE ]! D3 ~, i6 a o6 _& y1 E8 B0 n7 c# R# N
- // +----------------------------------------------------------------------& j5 ]7 J+ v" e$ Z, {5 H
- // | Copyright (c) 2010-2015 http://juhe.cn All rights reserved.- a- T q2 v; G6 F; B
- // +----------------------------------------------------------------------( @" ]; n; ~0 P" E% p$ u# t5 l
- // | Author: Juhedata <info@juhe.cn-->: j$ v2 E( N* ?* y: g) I
- // +----------------------------------------------------------------------
& A2 w; H' U4 s# S) l* f - 1 L0 O3 ]7 v% t9 C7 ]2 U7 p
- //----------------------------------
7 D1 U" |% h" g4 H* M x: D - // 图像识别调用示例代码 - 聚合数据% W5 O% V i: n
- // 在线接口文档:http://www.juhe.cn/docs/117
( _: w. e7 j1 | - //----------------------------------
4 }8 ]) C1 ~% A - 3 j O7 L. \8 Q( u' j7 U0 w
- header('Content-type:text/html;charset=utf-8');
$ h3 g7 w) W1 S1 F, o2 q3 d% K" J -
( L; x8 |2 f6 s0 G+ ?6 c! R4 M - ) a7 J2 f' e) r0 W6 Z
- //配置您申请的appkey
& c% o3 i. |: v1 z - $appkey = "*********************";% a9 S. \1 [2 E) h! N, d, l4 @
-
7 l0 n" x, `5 Y1 E - ( b% o7 k$ {: j' `
-
& |: y2 t1 T2 b/ Q% @8 w - # l6 u7 g/ }! c+ t
- //************1.图像上传************
0 }. u" o' ~ m- i3 I+ F( J - $url = "http://japi.juhe.cn/image_recognition/upload";: ^: e6 C9 n# i8 Q4 p
- $params = array(
- I% V# g5 z$ {6 s" G3 o( A - "file" => "",//上传的单张图片
( G* Q: H2 S7 S - "key" => $appkey,//APP Key n K% U% h F( H7 I
- "pname" => "",//包名: R1 B1 j! s, h
- );
6 T' H5 \7 M* V: W% w - $paramstring = http_build_query($params);
! m# F O y$ `, f: s+ Z( T4 \ - $content = juhecurl($url,$paramstring,1);
: J& N. ^) V8 T! K) G - $result = json_decode($content,true);; B8 B7 X1 l5 u0 K2 |
- if($result){
7 ^7 h/ W6 G' f" P' g - if($result['error_code']=='0'){
1 Y% s1 |8 n* J% O' }& r8 U9 ^ - print_r($result);
2 Z1 `+ e1 g5 F" ~9 Q2 P - }else{
& m& G/ t. A& s3 v& E - echo $result['error_code'].":".$result['reason'];
$ Q3 j' H* D0 M3 N - }5 \3 q. G* w+ y! N& F
- }else{! b, Y) @% b. z1 j% ~! C! H3 a* Q8 s
- echo "请求失败";
$ x6 G1 P5 w$ [- a0 t. [- ~ - }$ R/ v! p7 B v. U6 @
- //**************************************************
3 R; s5 N# V' a, Q, r7 E -
$ m3 G% k. W1 M, x! c* E6 o - 9 _' a! a+ Y$ T' W1 `: F
-
" b/ u l: {. Q' ]7 z4 [ - 4 x7 n- M( v! a1 V" V% |- e8 W
- //************2.查寻上传图像信息************
# x6 D' L- s$ E4 q. H* Y+ P - $url = "http://japi.juhe.cn/image_recognition/findAll";5 [. P* L( @+ Z3 e4 j
- $params = array(3 @* D* o% I, |6 D
- "key" => $appkey,//APP Key9 r% K+ M* V$ F/ Z
- );3 ~2 E# h- Y8 ^, G: R4 P
- $paramstring = http_build_query($params); V0 c, p% @. V [
- $content = juhecurl($url,$paramstring);
6 B; W% J: l' Y4 ~: @( D1 s7 M3 J4 l - $result = json_decode($content,true);$ a, n5 _/ ^2 K& B2 ]) j3 r
- if($result){- N/ `, i6 M h9 p3 P2 Q
- if($result['error_code']=='0'){
0 A j' |; b& m- T1 J - print_r($result);% V! }1 v8 G1 c$ Y: o- B
- }else{
* f3 E% u) S6 W- ? - echo $result['error_code'].":".$result['reason'];+ n$ T6 {& d0 ~2 D( d$ U
- }
; b. k$ O- W( d: G: O+ _9 C - }else{* y7 G( {, z' a
- echo "请求失败";
& N- E$ h; X4 a) L$ q( T - }; G) ?2 ` }# @) L$ T
- //**************************************************
; \" e/ A" d4 o) K3 G - 7 I( p8 J6 o* {; S: p' A5 I
- 1 P/ i) x7 b. }6 z* T+ g: u
- " _. y, F$ ]* f8 ?
-
9 M3 X" ?! o) P5 l6 ]! S - //************3.删除图像信息************
' H5 _$ z0 n6 r2 L ~ - $url = "http://japi.juhe.cn/image_recognition/delete";
) b* T; b+ Q- _8 v7 X0 u. P - $params = array(
% y- Q4 J# }0 p* Z' q8 @ - "key" => $appkey,//APP Key
& M$ O* G' ~) Z9 a$ p' V0 K$ B - "imageId" => "",//图片ID
% V/ P; I% s! }5 { - );
0 m. F- M5 C9 V9 E( }+ s( u1 Q - $paramstring = http_build_query($params);2 G$ X; b& ~; I% t: o
- $content = juhecurl($url,$paramstring);( f N0 D/ L" ^2 ^, z
- $result = json_decode($content,true);% @8 x( a/ j' E6 ]7 }' o3 l! w
- if($result){
4 P% _* T1 F) C8 v0 z - if($result['error_code']=='0'){
5 O1 N f+ O" d' t2 l( y7 z: w i - print_r($result);
u$ m- s. Z! _) c - }else{
. R0 n$ T& k" r# D - echo $result['error_code'].":".$result['reason'];0 q! `( |/ Z; W7 e' K
- }
% Z$ A2 B7 e7 l3 t( c1 f - }else{
: y- {( m _$ z8 C! _9 i - echo "请求失败";- E/ V h9 Z( q3 u) K( B
- }) O6 v5 q( s+ C, E4 L2 _" e! Y
- //**************************************************
# y4 W# @8 w5 O5 F9 h - ; L: h5 [% ?, x0 f$ {* z9 A8 a
- ; o% y4 f+ i; T4 p9 g! i$ Z& a
-
5 s) j0 I" P4 L ?. C; E - & G7 Z* J3 [5 P# f
- //************4.图像识别************: }) D& _9 E$ D4 x6 M( F% |4 x; j# t; B
- $url = "http://japi.juhe.cn/image_recognition/check";
; }. {! C$ W9 p0 R - $params = array(
0 Z( X$ c4 D4 P - "file" => "",//上传的图片
' @% Z* A% {5 J. O& h( ?: W' ^ - "key" => $appkey,//APP Key
6 k$ m! j- ~8 [! K - "pname" => "",//包名3 [! n" |6 h4 Y7 u# p5 Z8 x- r- K
- "device_name" => "",//设备名称(如android OS或iphone OS)
% G' i% H! F. j2 c. G$ A5 [! V - "device_version" => "",//设备版本(如:4.0.3)
6 X/ c5 {, Z$ Q) r& e - "latitude" => "",//纬度
# U) h# n0 _! P - "longitude" => "",//经度& l Q0 Y7 N! a$ N2 s* |
- "uuid" => "",//设备id" d* R/ P/ O! D9 T# u
- "zone" => "",//请求地区
7 h* y+ ]0 r4 N* G - );- n& P* F8 V5 T; P4 |: Q) s/ D
- $paramstring = http_build_query($params);
6 ]& F" z0 V% E- a: E" \ - $content = juhecurl($url,$paramstring,1);+ f: B q* c& `
- $result = json_decode($content,true);- V0 y# J$ K; [; f# G4 ]
- if($result){: W: u5 z2 x. a& K! l% x& v6 n* M+ @
- if($result['error_code']=='0'){
2 t) d6 y- }) D/ r- G - print_r($result);& z% H$ f3 L. a# }$ r
- }else{
b ~5 J x$ D! t! y - echo $result['error_code'].":".$result['reason'];
* _7 X, U2 x3 a - }
/ ^+ A% Z8 _: @: R& z3 t - }else{8 T# L8 A0 Q0 Y
- echo "请求失败";
. n* D) L, {% n# f5 y) I, L - }7 }( g/ ^) X E1 t( F5 R
- //**************************************************4 j8 S. ]; p: f; ]
-
" U" j0 ^+ ~" E2 k( c4 J% e G -
e8 U$ _. a" [5 L: o' F# N - + v+ D$ G1 }! a) ^* r
-
`* L/ F) d! U) W -
: r1 U: ~6 [6 B) e! w - /**
X3 A. }5 |' m - * 请求接口返回内容
. h) T4 ~. U W1 @1 Z( u& u& ~ - * @param string $url [请求的URL地址]: e* A4 \% W2 n8 g( Z: o
- * @param string $params [请求的参数]
% a1 m- h& i! F5 [. O! W8 O - * @param int $ipost [是否采用POST形式]. k0 N5 F0 d* U
- * @return string! z' }5 f) G5 b, U+ m8 R6 }
- */0 x l% l3 m2 E# T. ?% W
- function juhecurl($url,$params=false,$ispost=0){5 Z( S# z% N. p0 Z2 f8 E6 F4 c* q
- $httpInfo = array();
6 @) u5 Q) ^7 R$ s* X, O - $ch = curl_init();
2 d) {& B4 h# r; r6 l0 \ -
8 }6 {. M6 d" Q7 [9 O% X4 ] o, b - curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );
0 F% w8 b+ k7 c. a3 y$ C - curl_setopt( $ch, CURLOPT_USERAGENT , 'JuheData' );
( [6 d( w) }8 D5 \0 } E" m$ R* F - curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 );
, S3 G2 e: T2 V: _. y, @* Z - curl_setopt( $ch, CURLOPT_TIMEOUT , 60);
/ ^1 U( q& c1 ^- v+ w' X- K - curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );
: w: B% |1 h3 C- b0 P v! K - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
& }! |0 v% K! _% j/ [ - if( $ispost )8 {2 L Q' R3 e3 m- X* }! d. v
- {
2 R: a' { \8 R" w - curl_setopt( $ch , CURLOPT_POST , true );% v7 N2 |$ v% a. @4 e3 U
- curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );
2 ^$ |/ S! f' u0 ~ - curl_setopt( $ch , CURLOPT_URL , $url );( G# `% T9 ]' R6 |; K5 U
- }4 u' z6 v0 L7 I$ \8 G
- else
0 D- G8 j5 [+ _8 S. h& y - {4 v8 Z- F- K* U* ^# _* d
- if($params){
) o' d$ K8 S& l" c - curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );
% N! Z: t, d2 A! Q/ m& ?2 j. y - }else{) X5 h5 r5 \" l
- curl_setopt( $ch , CURLOPT_URL , $url);
5 h5 O# V* t$ b3 z - }/ \* g3 P& y5 Q" m
- }
( d8 ^. O# s. r) c& ` - $response = curl_exec( $ch );3 S0 a: G& K8 b: C
- if ($response === FALSE) {1 l$ L2 _, }8 l
- //echo "cURL Error: " . curl_error($ch);8 r# f( j1 n2 g/ Y- U" V/ R) A, v
- return false;9 X3 g' y8 H1 \, h0 G1 x
- }8 X! b+ [: {% _! O
- $httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE );6 c; h: B- \, e2 L* u
- $httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) );
# d T/ O% Q9 n% w' x, B4 E$ C2 V - curl_close( $ch );3 `4 d* S" v: d6 F
- return $response;. ~: u! {) p, M" g- i" h
- }
复制代码 ! R6 r' R+ _9 K) l2 G
" R( Q& H& E% D) s; v- m" { |
|