管理员
论坛积分
分
威望 点
贡献值 个
金币 枚
|
提供B2B的移动商务解决方案,通过图像识别技术,通过摄像头扫描直接查询和购买商品。
# o0 A. t3 N) W1.添加商品信息1 R r- m) ?' m, B+ l
2.添加图片
2 f& Q+ v# v, d- w# K$ g* ]3.查询所有产品
+ n1 r8 p4 @: F' J( ^1 i4.查询某个具体产品信息# \7 ?5 c4 \8 o l% u1 E( V
5.删除某个产品+ |% ]6 Z8 v# M- b
6.删除图片. \- y& e3 s& f: ~6 e5 X
7.图像识别
. j7 P' w/ {! g M+ p% d8 w5 B, L; ~) V5 L. C% |. w+ W
图像识别API文档:https://www.juhe.cn/docs/api/id/117,申请后生成AppKey8 q! h7 e8 o5 S9 u0 L: Q8 x
! Y0 c/ k1 B2 r- NPHP示例:
1 {9 n" \; I; _5 Q( j: k, Z- <!--?php8 N5 T; Q# y: R
- // +----------------------------------------------------------------------
& o5 W# U/ b1 r8 w3 Z - // | JuhePHP [ NO ZUO NO DIE ]5 A5 Y3 n2 T1 ?3 `. {" a
- // +----------------------------------------------------------------------8 I) z/ S% A3 N& e$ _
- // | Copyright (c) 2010-2015 http://juhe.cn All rights reserved.
" m3 D; \! E; z2 w$ D( z5 l - // +----------------------------------------------------------------------3 G: a$ _7 c' u; D( w% _% ]; [# T
- // | Author: Juhedata <info@juhe.cn-->
7 L8 K2 T- A; F- [! S7 | - // +----------------------------------------------------------------------
# b6 E; }) s' F8 k6 d' h: W; \ -
1 P5 F c# [( Z4 Z1 ?: o, p7 _ - //----------------------------------, G' A& g! K2 k
- // 图像识别调用示例代码 - 聚合数据4 A+ L* C7 t+ F9 [, _4 a
- // 在线接口文档:http://www.juhe.cn/docs/117' T6 f% \7 Y0 N' z c4 @0 Y9 K
- //----------------------------------
( ?! l3 p% q, y9 `: a( E -
7 `( Y0 O N6 q8 F/ u - header('Content-type:text/html;charset=utf-8');
' r1 J: e$ t9 X6 Z! Y1 ? ~ -
* k+ b. d L) n -
' j. l" y) ]/ l - //配置您申请的appkey
$ o5 K) V2 w2 e$ ]+ t8 v - $appkey = "*********************";
8 f+ n/ V1 r9 m - ( ^0 [5 L/ N$ X4 @
-
: L1 h3 G3 y" t -
, t: @: s$ {5 l - ' o: [; z6 Z7 w ~
- //************1.图像上传************ G- j$ i# ^3 w& }
- $url = "http://japi.juhe.cn/image_recognition/upload";; | T) n3 h9 v3 P0 z+ g6 U4 ]4 c3 O
- $params = array(
1 |- l) Y5 Q( ^; q X - "file" => "",//上传的单张图片
: x5 ]) o/ L0 k - "key" => $appkey,//APP Key
/ k( |0 M) I& Q - "pname" => "",//包名
0 y" B& U, ~; m' n8 j5 B - );6 g1 Z& }0 d4 t" O3 y
- $paramstring = http_build_query($params);
1 Z1 o! ]3 @" d: d4 u# u - $content = juhecurl($url,$paramstring,1);& T. s6 a$ i) M0 O
- $result = json_decode($content,true);$ K9 i1 V1 R2 X
- if($result){
; k& u+ j* w* V) S% n5 I) g1 X - if($result['error_code']=='0'){+ C% u7 ]% S2 v' n8 {1 h8 h4 G
- print_r($result);6 u) M' Z- p* ^7 u1 [, m3 a
- }else{0 f6 b/ q" a, B* I
- echo $result['error_code'].":".$result['reason'];
/ ~. Y4 l; L: F" f) j0 ] - }* w0 H6 ^, ~6 ?. O; |& Y+ F
- }else{
; `* I- r2 O$ h# h) p - echo "请求失败";
- z a& w$ m D - }
/ z# s% k; I+ R* ?, X! g - //**************************************************
5 z e+ M+ U& t - $ K( K' }0 P$ g3 w& f. T- J
- & V0 l$ p4 ]) ~+ q4 h2 D
- # K) q* V# O y" |2 m, t+ [, h
-
# @+ Y% D$ Q6 i3 X - //************2.查寻上传图像信息************6 f0 e8 w c" x. k N! |) w
- $url = "http://japi.juhe.cn/image_recognition/findAll";. ]' s6 w+ B2 A( I2 _0 ]
- $params = array(+ F# ]- r# ~2 f* o8 O* a _5 P
- "key" => $appkey,//APP Key
5 ?! y2 a& g0 T" X- m) @ - );
2 p, w6 V" T( k* B$ J$ [ - $paramstring = http_build_query($params);
2 B* U( M. B" X# @ - $content = juhecurl($url,$paramstring);! \. A. `% j5 Q, b' o2 }8 G
- $result = json_decode($content,true);
7 d6 l% s6 }# f: U - if($result){3 O& {5 I2 y6 c) e* p$ U
- if($result['error_code']=='0'){! Z& ~* d; k/ }( @$ h) w1 z/ h1 I$ |
- print_r($result);$ I* |- c8 j% M F2 f8 E; Z
- }else{& K. c# O( K* A# v
- echo $result['error_code'].":".$result['reason'];
6 G" o0 U3 a: \: {5 z+ t$ x8 V/ ] - }9 ]+ O6 O5 ]! ]' r, X
- }else{
& s1 F' R( y+ i2 ]# @ - echo "请求失败";
0 U3 |1 j$ i7 F' b+ U( T. ~7 i - }$ F a0 h* o# ^1 y% M1 v+ w2 ?
- //**************************************************
9 }. `5 q, |8 I- x+ d2 N -
1 }- r, P) I. W6 y4 d, f( W) [ - # D" Q$ R. G: h7 j5 _% }* Y
- , X0 A) K# t0 R2 u0 e
- 1 Y8 R+ `) U# z6 u, p
- //************3.删除图像信息************, E0 B7 M$ R/ O0 o
- $url = "http://japi.juhe.cn/image_recognition/delete";, z/ w- R4 Q" w
- $params = array(
" H# H& D2 q; m6 ]) W) P - "key" => $appkey,//APP Key
! K. z2 i5 H/ y1 l* S$ y - "imageId" => "",//图片ID! S; ]8 D3 \- a" s- V
- );* Y Q$ d1 L/ y1 g+ N) X" Z
- $paramstring = http_build_query($params);
9 X1 H7 u$ `" y4 c9 J) k9 ` - $content = juhecurl($url,$paramstring);, s4 r j) n/ y% ~
- $result = json_decode($content,true);
$ P6 t( S3 ?; i k - if($result){# ^& k. t( L F6 k" X* L
- if($result['error_code']=='0'){! k6 b. T* \/ L7 G3 l
- print_r($result);; M) w7 W+ l& x4 |
- }else{. X' e$ ]7 w4 }) W
- echo $result['error_code'].":".$result['reason'];
) ^$ J, C- F. p: ]( S3 E - }
, t3 T; ?" w J2 v - }else{
9 H/ o5 H2 _! j - echo "请求失败";
( _8 F, P' g% x% Y - }
8 a, Z3 j1 v5 B% O6 J' l - //**************************************************, m9 M/ D! x: ?% T( }6 Z! q* z
-
% w# t' X/ B9 Q: m7 I# @ -
: R7 U0 i+ t: |8 \, r9 N( ` -
' {, F7 z d0 N- W -
1 m: A2 L; @& R+ k. { - //************4.图像识别************
/ T+ `: q6 E$ S' g - $url = "http://japi.juhe.cn/image_recognition/check";6 v2 f5 f3 f# \
- $params = array(6 H' m9 f+ T2 P9 Q' V
- "file" => "",//上传的图片
, b) X- S9 [6 ? - "key" => $appkey,//APP Key" t" B. z3 |2 L
- "pname" => "",//包名
+ [. }, ~' L! Q& G. n! [# { - "device_name" => "",//设备名称(如android OS或iphone OS)
9 }1 Q5 y% ?, o0 @ R - "device_version" => "",//设备版本(如:4.0.3)& h. l" b f( R2 @' P
- "latitude" => "",//纬度
* X* ~0 m( M [& L- @# I$ I! W - "longitude" => "",//经度2 A* W- Y, N4 @6 F: ?; w7 A
- "uuid" => "",//设备id
# S$ }9 q% I# l1 r# B5 R - "zone" => "",//请求地区: B( E8 t) P3 ~+ S2 T) T B$ G5 A
- );
* F; }& X( [' Y. P# F# S/ F - $paramstring = http_build_query($params);
; O$ G P/ N1 u2 Q: j! V; K - $content = juhecurl($url,$paramstring,1);& R$ k8 J9 d( x4 p( j
- $result = json_decode($content,true);# x# F$ M! b' \2 @ Z4 t( V& p* O
- if($result){3 n: ]/ T# i% U7 S
- if($result['error_code']=='0'){
9 G( L+ [* m" G: E2 j! b8 e: k - print_r($result);
, M( {; o+ [2 A6 Q C8 R B* N - }else{. s& U$ D( z) @
- echo $result['error_code'].":".$result['reason'];3 I+ O( Y% i5 U$ d0 P
- }
* M$ z, ^* `8 c( B( b$ \# p9 d - }else{
/ q" p8 a) \! B6 R1 w' @# y& n4 K - echo "请求失败";) |! j \0 [4 M
- }9 _" r* Q) B* G5 a% N4 y; ~' w5 ~
- //**************************************************2 t5 Y1 g) g% \& X
-
1 W) l" k, t& j) S: ?7 c& a3 y3 N; m+ X. d - ' [/ T0 X @, j7 D' n0 Q
-
; F( k/ H3 s( [+ I( M - - C; j) I% u- k7 Z5 U2 S
-
, Z% w( y) r+ r1 x) y9 ] - /**( F# f U) \& D8 c0 y5 u
- * 请求接口返回内容' W, `: }- X4 W* s2 _/ c
- * @param string $url [请求的URL地址]/ Y" l1 _' H$ W3 b
- * @param string $params [请求的参数]4 x# A1 j6 o$ c9 F; S
- * @param int $ipost [是否采用POST形式]
8 q3 x1 U# d( I0 h2 y4 } - * @return string
9 d( o) G$ k. K: c8 n - */
' ?( }, y6 ^( P$ { - function juhecurl($url,$params=false,$ispost=0){
4 e Z9 N. r8 C4 o - $httpInfo = array();5 H/ A8 Z9 [8 j. V# F1 _+ P% J7 e
- $ch = curl_init();
# p2 j/ q( a3 I - 3 x2 D7 t8 U! {, {5 r
- curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );
4 R; b7 g. H, ^& b* S - curl_setopt( $ch, CURLOPT_USERAGENT , 'JuheData' );
& {! a/ ]3 l1 B! Z W+ X2 g - curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 );
P5 u* C1 S9 f& P4 N* W - curl_setopt( $ch, CURLOPT_TIMEOUT , 60);$ e f% b0 c; L. r& `7 B% r; H
- curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );
. T$ A/ _4 f* n' p4 ~: S - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
' z: |; N9 M9 X8 [/ Y! l - if( $ispost )
$ F! ^# r( E4 s- T9 y% W& r3 w - {
& }' ^- u; L+ [- x7 K% u - curl_setopt( $ch , CURLOPT_POST , true );# B% y0 n& C& J, j) H
- curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );/ { ^, n3 _" H4 D+ u% `) t
- curl_setopt( $ch , CURLOPT_URL , $url );% @1 V3 l- L9 R5 P9 |; l
- } _- c; B7 @* V0 w5 Q' K
- else
* t% ^/ ^, G5 ~2 z - {
3 w; P% v# B+ r- @5 f$ ? - if($params){9 k. b# F* M9 n. ] o% p4 {7 Z
- curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );
7 k8 k# {3 Z( j$ s3 `/ M7 k8 } - }else{1 X$ V$ R B+ z
- curl_setopt( $ch , CURLOPT_URL , $url);% Z. I! \/ R7 i: ]* C; @2 q
- }( r0 e/ k4 R0 z, \5 [
- }
' |; e: [8 I* G3 _1 u3 `! X - $response = curl_exec( $ch );! J; j7 h* p \$ d+ \! Z# `
- if ($response === FALSE) {) e! L5 b& l) ?: s4 ?) [
- //echo "cURL Error: " . curl_error($ch);7 h1 k8 m0 Q0 G- Y
- return false;1 \ C2 s4 B( T: T5 G: y5 v
- }
1 a. p2 a) }1 P3 |" I0 S: ]/ w' \ - $httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE );( g. K( O6 Z2 H
- $httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) );
0 b; u" x7 H" F! [: U - curl_close( $ch );
* }. S: `2 I( y. k - return $response;
" ^5 x6 A T; d6 ^ - }
复制代码 9 L( ^9 p: N$ I" F5 p. T% g: d
6 z( }8 p% d9 v* p |
|